深度学习项目中在yaml文件中定义配置,以及使用的python的PyYAML库包读取解析yaml配置文件
YAML (YAML Aint Markup Language)是一种标记语言,通常以.yml或者.yaml为后缀的文件,是一种直观的能够被电脑识别的数据序列化格式,并且容易被人类阅读,容易和脚本语言交互的,可以被支持YAML库的不同的编程语言程序导入,一种专门用来写配置文件的语言。可用于如: Java,C/C++, Ruby, Python, Perl, C#, PHP等。
作用类似于json 主要用于参数配置
YML语法
大小写敏感
使用缩进表示层级关系
缩进时不允许使用Tab键,只允许使用空格。
缩进的空格数目不重要,只要相同层级的元素左侧对齐即可
#表注释
- 约定
k: v 表示键值对关系,冒号后面必须有一个空格
使用空格的缩进表示层级关系,空格数目不重要,只要是左对齐的一列数据,都是同一个层级的
大小写敏感
缩进时不允许使用Tab键,只允许使用空格。
松散表示,Java中对于驼峰命名法,可用原名或使用-代替驼峰,如java中的lastName属性,在yml中使用lastName或 last-name都可正确映射。 - 键值关系
(以Java语言为例,其它语言类似)对于键与值主要是看能否表示以下内容。普通的值(数字、字符串、布尔)、日期、对象、数组、集合等。
- 普通值(字面量)
k: v:字面量直接写;
字符串默认不用加上单引号或者双绰号;
“”: 双引号;不会转义字符串里面的特殊字符;特殊字符会作为本身想表示的意思
name: “zhangsan \n lisi”:输出;zhangsan 换行 lisi
‘’:单引号;会转义特殊字符,特殊字符最终只是一个普通的字符串数据
- 数组:一组按次序排列的值,序列 / 列表
数组前加有 “-” 符号,符号与值之间需用空格分隔
后缀为 :yml 或者yaml
- 冒号:后必须有空格
MODEL:
PRETRAIN_PATH: '/home/enrsuwg/.cache/torch/hub/checkpoints/resnet50-19c8e357.pth'
INPUT:
SIZE_TRAIN: [256, 128]
SIZE_TEST: [256, 128]
PROB: 0.5 # random horizontal flip
RE_PROB: 0.5 # random erasing
PADDING: 10
DATASETS:
NAMES: ('market1501')
DATALOADER:
SAMPLER: 'softmax'
NUM_WORKERS: 8
SOLVER:
OPTIMIZER_NAME: 'Adam'
MAX_EPOCHS: 120
BASE_LR: 0.00035
BIAS_LR_FACTOR: 1
WEIGHT_DECAY: 0.0005
WEIGHT_DECAY_BIAS: 0.0005
IMS_PER_BATCH: 64
STEPS: [30, 55]
GAMMA: 0.1
WARMUP_FACTOR: 0.01
WARMUP_ITERS: 5
WARMUP_METHOD: 'linear'
CHECKPOINT_PERIOD: 20
LOG_PERIOD: 20
EVAL_PERIOD: 20
TEST:
IMS_PER_BATCH: 128
OUTPUT_DIR: "/home/haoluo/log/reid/market1501/softmax_bs64_256x128"
# model.yaml
# Copyright 2019 Xilinx Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
description: FPN(ResNet18) segmentation on EDD2020.
input size: 320*320
float ops: 45.3G
task: segmentation
framework: caffe
prune: 'no'
version: 1.3
files:
- name: cf_FPN-resnet18_EDD_320_320_45.3G_1.3
type: float & quantized
board: GPU
download link: https://www.xilinx.com/bin/public/openDownload?filename=cf_FPN-resnet18_EDD_320_320_45.3G_1.3.zip
checksum: 9147cfb2a8e09442988bf8cc21c2c305
- name: FPN_Res18_Medical_segmentation
type: xmodel
board: zcu102 & zcu104
download link: https://www.xilinx.com/bin/public/openDownload?filename=FPN_Res18_Medical_segmentation-zcu102_zcu104-r1.3.1.tar.gz
checksum: f19949ab5b4250e79e25bda115ab321a
- name: FPN_Res18_Medical_segmentation
type: xmodel
board: vck190
download link: https://www.xilinx.com/bin/public/openDownload?filename=FPN_Res18_Medical_segmentation-vck190-r1.3.1.tar.gz
checksum: 78e34bae159c2a0ef9c1cd942d90aaa8
- name: FPN_Res18_Medical_segmentation
type: xmodel
board: u50
download link: https://www.xilinx.com/bin/public/openDownload?filename=FPN_Res18_Medical_segmentation-u50-r1.3.1.tar.gz
checksum: 9e4cba54a501a808a7866e6b8bb963fc
- name: FPN_Res18_Medical_segmentation
type: xmodel
board: u50lv9e & u50lv10e & u280
download link: https://www.xilinx.com/bin/public/openDownload?filename=FPN_Res18_Medical_segmentation-u50lv-u280-r1.3.1.tar.gz
checksum: b4412be95bacb53d41db11bb1e780bae
- name: FPN_Res18_Medical_segmentation
type: xmodel
board: u50-v3me & u50lv-v3me & u280-v3me
download link: https://www.xilinx.com/bin/public/openDownload?filename=FPN_Res18_Medical_segmentation-u50-u50lv-u280-v3me-r1.3.1.tar.gz
checksum: bf5195dc8cad6d5006bb062da1812ad5
license: https://github.com/Xilinx/Vitis-AI/blob/master/LICENSE