王权富贵:写python工程中配置文件的写法
目录
对应配置文件的初始
对应配置的更新函数
python接口的调用
对应配置文件的初始
#步骤1,导入对应库
# `pip install easydict` if you don't have it
from easydict import EasyDict as edict#步骤2,初始化
__C = edict()# Consumers can get config by:
# from fast_rcnn_config import cfg
#步骤3,重命名
cfg = __C#
# Training options
#
#步骤4,对应类初始化
__C.TRAIN = edict()# Initial learning rate
#步骤5,赋值
__C.TRAIN.LEARNING_RATE = 0.001
............................................#
# Testing options
#
__C.TEST = edict()# Scale to use during testing (can NOT list multiple scales)
# The scale is the pixel size of an image's shortest side
__C.TEST.SCALES = (600,)# Max pixel size of the longest side of a scaled input image
__C.TEST.MAX_SIZE = 1000# Overlap threshold used for non-maximum suppression (suppress boxes with
# IoU >= this threshold)
__C.TEST.NMS = 0.3
...............................................
EasyDict可以让你像访问属性一样访问dict里的变量
>>> from easydict import EasyDict as edict
>>> d = edict({'foo':3, 'bar':{'x':1, 'y':2}})
>>> d.foo
3
>>> d.bar.x
1>>> d = edict(foo=3)
>>> d.foo
3
EasyDict库详细参考。
对应配置的更新函数
def _merge_a_into_b(a, b):"""Merge config dictionary a into config dictionary b, clobbering theoptions in b whenever they are also specified in a."""if type(a) is not edict:returnfor k, v in a.items():# a must specify keys that are in bif k not in b:raise KeyError('{} is not a valid config key'.format(k))# the types must match, tooold_type = type(b[k])if old_type is not type(v):if isinstance(b[k], np.ndarray):v = np.array(v, dtype=b[k].dtype)else:raise ValueError(('Type mismatch ({} vs. {}) ''for config key: {}').format(type(b[k]),type(v), k))# recursively merge dictsif type(v) is edict:try:_merge_a_into_b(a[k], b[k])except:print(('Error under config key: {}'.format(k)))raiseelse:b[k] = vdef cfg_from_file(filename):"""Load a config file and merge it into the default options."""import yamlwith open(filename, 'r') as f:yaml_cfg = edict(yaml.load(f))_merge_a_into_b(yaml_cfg, __C)def cfg_from_list(cfg_list):"""Set config keys via list (e.g., from command line)."""from ast import literal_evalassert len(cfg_list) % 2 == 0for k, v in zip(cfg_list[0::2], cfg_list[1::2]):key_list = k.split('.')d = __Cfor subkey in key_list[:-1]:assert subkey in dd = d[subkey]subkey = key_list[-1]assert subkey in dtry:value = literal_eval(v)except:# handle the case when v is a string literalvalue = vassert type(value) == type(d[subkey]), \'type {} does not match original type {}'.format(type(value), type(d[subkey]))d[subkey] = value
python接口的调用
def parse_args():parser = argparse.ArgumentParser(description='Train a Fast R-CNN network')parser.add_argument('--dataset', dest='dataset',help='training dataset',default='pascal_voc', type=str)..................................................args = parser.parse_args()return argsif __name__ == '__main__':args = parse_args()print('Called with args:')print(args)if args.cfg_file is not None:cfg_from_file(args.cfg_file)if args.set_cfgs is not None:cfg_from_list(args.set_cfgs)cfg.USE_GPU_NMS = args.cudaprint('Using config:')pprint.pprint(cfg)
王权富贵:写python工程中配置文件的写法相关推荐
- python拼音怎么写-Python 获取中文字拼音首个字母的方法
Python:3.5 代码如下: def single_get_first(unicode1): str1 = unicode1.encode('gbk') try: ord(str1) return ...
- python中怎么写注释_Python中注释的写法
Python中注释的写法 #:使用井号进行单行注释 Python中貌似没有提供多行注释,不过我们可以利用三引号的多行字符串来进行多行注释 """ 多行注释内容 多行注释内 ...
- 王权富贵:pytorch,残差块的写法
ResNet34网络构建:主体结构是 # 我们这里以 ResNets34 为例子# 先实现一个Block class Block(nn.Module):def __init__(self, in_ch ...
- Python包中__init__.py文件的作用和用法
在Python工程中,我们经常可以看到带有"__init__.py"文件的目录,在PyCharm中,带有这个文件的目录被认为是Python的包目录,与目录的图标有不一样的显示.如下 ...
- python创建配置文件_如何写python的配置文件
一.创建配置文件 在D盘建立一个配置文件,名字为:test.ini 内容如下: [baseconf] host=127.0.0.1 port=3306 user=root password=root ...
- python怎么创建配置文件_如何写python的配置文件
一.创建配置文件 在D盘建立一个配置文件,名字为:test.ini 内容如下: [baseconf] host=127.0.0.1 port=3306 user=root password=root ...
- python配置文件解析_Python中配置文件解析模块-ConfigParser
Python中有ConfigParser类,可以很方便的从配置文件中读取数据(如DB的配置,路径的配置). 配置文件的格式是: []包含的叫section, section 下有option=valu ...
- Spring-Boot:写出来的网站访问不到静态资源?怎样通过url访问SpringBoot项目中的静态资源?localhost:8989/favicon.ico访问不了工程中的图标资源?
Spring-Boot:Spring-Boot写出来的网站访问不到静态资源?怎样通过url访问SpringBoot项目中的静态资源?localhost:8989/favicon.ico访问不了工程中的 ...
- 在IIS中写Python的CGI脚本
原文:怎样在IIS中写Python的CGI脚本 1.安装好Python: 2.配置IIS: a.打开管理工具-〉Internet信息服务: b.在网站属性上右键,进入属 ...
最新文章
- SHOW PROCESSLIST 命令详解 (查看锁表)
- pybind 编码h264
- 基于深度学习的多目标跟踪:从UMA Tracker出发谈谈SOT类MOT算法
- 如何设置eclipse下查看java源码
- Cobbler体验小记
- 概率占据图(POM)算法理解
- opencv 的norm_22、OpenCV用卷积Filter2D进行滤波器
- KVM之一:安装准备(基于CentOS6.7)
- php aes java_AES php java 互转
- 软件工程 speedsnail 冲刺8
- 全国行政区划代码(json对象)---包含键值对的城市代号和城市名称的json对象代码(不包括县级市)
- passing '' as 'this' argument discards qualifiers [-fpermissive]
- for的用法详解,for循环完全攻略
- 计算机网络的组成与分类
- 机械键盘用哪种轴的好?
- 3.6 51单片机-动态数码管
- c++实现sqrt函数功能
- 今天才发现,手机外放声音小,这样设置一下,轻松增大手机音量
- mac里python注释的快捷键_新手小白学Python必备编程利器Pycharm快捷键大全(Win+Mac)...
- Python编程练习(三):21 - 30