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

2024-04-20 09:18:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于下例中使用的batch_size参数的问题。你知道吗

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?你知道吗


Tags: thehttpsgithubnodedefaultdata参数size
1条回答
网友
1楼 · 发布于 2024-04-20 09:18:05

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

ArgumentParser generates the value of dest by taking the first long option string and stripping away the initial string ... Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name

在这种情况下,long-option batch-size,因此默认情况下dest设置为batch_size

相关问题 更多 >