config.py和cfg_file(res101.yml)

config.py

  • cfg_from_file(filename)
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)
  • _merge_a_into_b(a, b)
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

  • res101.yml
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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • 1.创建文件夹 !/bin/sh mkdir -m 777 "%%1" 2.创建文件 !/bin/sh touch...
    BigJeffWang阅读 10,198评论 3 53
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 8,926评论 0 6
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,779评论 18 399
  • 下雨的周末,没有约会,没有出门。反正平日里也是没有约会,没有出门的。画些小物件,爱不释手。
    阿i遥阅读 334评论 0 0