首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当不使用dest时,argparse如何确定参数名称?

当不使用dest时,argparse如何确定参数名称?
EN

Stack Overflow用户
提问于 2019-02-22 01:30:25
回答 1查看 51关注 0票数 2

关于下面示例中使用的batch_size参数,我有一个问题。

代码语言:javascript
复制
https://github.com/pytorch/examples/blob/master/imagenet/main.py#L150


parser.add_argument('-b', '--batch-size', default=256, type=int,
                    metavar='N',
                    # dest='batch_size' why this is not needed? 
                    help='mini-batch size (default: 256), this is the total '
                         'batch size of all GPUs on the current node when '
                         'using Data Parallel or Distributed Data Parallel')

# missing code

args.batch_size = int(args.batch_size / ngpus_per_node)

我的问题是,如果没有dest参数,如何从命令行解析和保存batch_size

EN

回答 1

Stack Overflow用户

发布于 2019-02-22 01:33:55

来自https://docs.python.org/2/library/argparse.html#dest

ArgumentParser通过获取第一个长选项字符串并去掉初始的--字符串来生成dest的值...所有内部-字符都将转换为_字符,以确保字符串是有效的属性名称

在本例中,long-option--batch-size,因此缺省情况下,dest设置为batch_size

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54812978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档