yacs介绍、安装、使用

yacs介绍、安装、使用

1.yacs介绍

yacs的作者大名鼎鼎的Ross Girshick,faster-rcnn的作者。github地址:https://github.com/rbgirshick/yacs

yacs是一个轻量级用于定义和管理系统配置的开源库,是科学实验软件中常用的参数配置。在机器学习、深度学习模型训练过程中的超参数配置(卷积神经网络的深度,初始学习率等)。科学实验的重现性至关重要,因此,需要记录实验过程中的参数设置,以达到后期进行实验的重现。yacs使用一种简单的,可读的yaml格式。

2.yacs安装

git clone https://github.com/rbgirshick/yacs.git
python setup.py install

3.yacs使用

3.1 建立可配置参数文件并设置默认值

建立可配置文件,通常命名为config.py或者default.py,该文件包含了所有可配置的参数,并为每个参数设置了默认值。

config.py

from yacs.config import CfgNode as CN

_C=CN()
_C.SYSTEM=CN()
_C.SYSTEM.NUM_GPUS = 8
_C.SYSTEM.NUM_WORKERS = 4
 
_C.TRAIN = CN()
_C.TRAIN.HYPERPARAMETER_1 = 0.1
_C.TRAIN.SCALES = (2, 4, 8, 16)

def get_cfg_defaults():
	return _C.clone() #局部变量使用形式
 
cfg = _C

3.2 创建yaml配置文件

通常情况下,为每个实验建立一个yaml文件,每个配置文件中仅包含该实验中正在修改的选项。

config.yaml

SYSTEM:
  NUM_GPUS: 2
TRAIN:
  SCALES: (1, 2)

3.3 使用配置文件

进行初始设置以后,使用freeze()函数将设置值冻结,防止配置信息被修改。如下,可以通过直接导入cfg作为全局变量进行访问,也可以将cfg的复制作为参数进行传递,这种使用为cfg作为局部变量使用。

main.py

#from config import get_cfg_defaults #局部变量
from config import cfg
 
if __name__ == "__main__":
    #cfg = get_cfg_defaults() #局部变量使用
    cfg.merge_from_file("config.yaml")
    cfg.freeze()
 
    cfg2 = cfg.clone()
    cfg2.defrost()
    cfg2.TRAIN.SCALES = (8, 32, 64)
    cfg2.freeze()
 
    print("cfg:")
    print(cfg)
    print("cfg2:")
    print(cfg2)

输出结果为:

cfg:
SYSTEM:
  NUM_GPUS: 2
  NUM_WORKERS: 4
TRAIN:
  HYPERPARAMETER_1: 0.1
  SCALES: (1, 2)
cfg2:
SYSTEM:
  NUM_GPUS: 2
  NUM_WORKERS: 4
TRAIN:
  HYPERPARAMETER_1: 0.1
  SCALES: (8, 32, 64)

4 参考

1.https://github.com/rbgirshick/yacs

YACS 是一个强大的 PHP 脚本,可以让你维护一个动态的 Web 服务器。特性:- Runs on your own server, or on a shared web site- Post articles with web forms, by e-mail, or remotely (w:bloggar)- Embed images and photos in articles --automatic resize- Each section can be a weblog, a discussion board, a book of cooking recipes,etc, or even a plain list of articles- Overlay interface for PHP developers, to add extra functionality to articles,such as polls or cooking recipes- Display the content tree in Freemind- Comments, with quoting- Archives per week and per month- The home page is updated automatically on article publishing- Categories, sub-categories, etc. --Build your own Yahoo! or DMOZ...- Real-time meetings with community members- Private discussions and messages- Search on any word --text of articles is fully indexed- Multiple authors --actually, a community of contributors- Articles are visible only on publication after review by editors- Articles and sections can have dead-line to limit visibility over time- A straightforward control panel, and a set of configuration panels- File upload to articles , sections or categories- Attach links to articles, sections or categories- A comprehensive set of UBB-like codes are available to beautify your posts- Integrated support of TinyMCE and of FCKEditor- Fully customizable skins- Easy integration of Google Maps- Add a comprehensive web interface to existing collections of files- Support audio-on demand and video-on demand- Automatic web slideshow for shared photos- RSS syndication- Easy installation- XML-RPC interface (implementing the Blogger API and metaWeblog API) 标签:YACS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值