config.py
def cfg_from_file(filename):
"""Load a config file and merge it into the default options."""
import yaml
with open(filename, 'r') as f:
yaml_cfg = edict(yaml.load(f))#将yml文件转换为字典
_merge_a_into_b(yaml_cfg, __C)
def _merge_a_into_b(a, b):;将文件a的内容替换到b
"""Merge config dictionary a into config dictionary b, clobbering the
options in b whenever they are also specified in a.
"""
if type(a) is not edict:
return
for k, v in a.items():;key,value遍历字典
# a must specify keys that are in b;a的key必须在b中
if k not in b:
raise KeyError('{} is not a valid config key'.format(k))
# the types must match, too;a的value必须与b对应的value类型一致
old_type = type(b[k])
if old_type is not type(v):
if isinstance(b[k], np.ndarray):;判断是否是同一实例,ndarray:N维数组(简称数组)对象,存储单一数据类型的N维数组
v = np.array(v, dtype=b[k].dtype);np.array()一个函数,返回ndarray实例
else:
raise ValueError(('Type mismatch ({} vs. {}) '
'for config key: {}').format(type(b[k]),
type(v), k))
# recursively merge dicts;递归合并字典
if type(v) is edict:
try:
_merge_a_into_b(a[k], b[k]);递归处理
except:
print(('Error under config key: {}'.format(k)))
raise
else:
b[k] = v
cfg_file
EXP_DIR: res101
TRAIN:
HAS_RPN: True
IMS_PER_BATCH: 1
BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
RPN_POSITIVE_OVERLAP: 0.7
RPN_BATCHSIZE: 256
PROPOSAL_METHOD: gt
BG_THRESH_LO: 0.0
DISPLAY: 20
BATCH_SIZE: 256
DOUBLE_BIAS: False
SNAPSHOT_PREFIX: res101_faster_rcnn
TEST:
HAS_RPN: True
POOLING_MODE: crop