深度学习代码中argparse以及yaml文件的使用
程序员大白
共 2533字,需浏览 6分钟
·
2022-03-18 19:43
点击上方“程序员大白”,选择“星标”公众号
重磅干货,第一时间送达
01
if __name__ == '__main__':
parse = argparse.ArgumentParser()
parse.add_argument('--num_batches', type=int, default=50, help='the num of batch')
parse.add_argument('--num_window', type=int, default=5, help='the num of window')
parse.add_argument('--weight', type=str, default= '../pretrain.pth', help='the path of pretrained model')
opt = parse.parse_args()
import argparse
def main(opt):
print(opt.num_batches)
if __name__ == '__main__':
parse = argparse.ArgumentParser()
parse.add_argument('--num_batches', type=int, default=50, help='the num of batch')
parse.add_argument('--num_window', type=int, default=5, help='the num of window')
parse.add_argument('--weight', type=str, default= '../pretrain.pth', help='the path of pretrained model')
opt = parse.parse_args()
main(opt)
02
device: 'cpu'
data:
train_path: 'data/train'
test_path: 'test/train'
num: 1000
03
def read_yaml(path):
file = open(path, 'r', encoding='utf-8')
string = file.read()
dict = yaml.safe_load(string)
return dict
path = 'config.yaml'
Dict = read_yaml(path)
device = Dict['device']
print(device)
train_path = Dict['data']['train_path']
print(train_path)
import yaml
def read_yaml(path):
file = open(path, 'r', encoding='utf-8')
string = file.read()
dict = yaml.safe_load(string)
return dict
path = 'config.yaml'
Dict = read_yaml(path)
device = Dict['device']
print(device)
train_path = Dict['data']['train_path']
print(train_path)
04
推荐阅读
关于程序员大白
程序员大白是一群哈工大,东北大学,西湖大学和上海交通大学的硕士博士运营维护的号,大家乐于分享高质量文章,喜欢总结知识,欢迎关注[程序员大白],大家一起学习进步!
评论