未被识别的参数:True

3

代码:

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='Build dataset')
    parser.add_argument('jpeg_dir', type=str, help='path to jpeg images')
    parser.add_argument('nb_channels', type=int, help='number of image channels')
    parser.add_argument('--img_size', default=256, type=int,
                        help='Desired Width == Height')
    parser.add_argument('--do_plot', action="store_true",
                        help='Plot the images to make sure the data processing went OK')
    args = parser.parse_args()

错误:

$ python make_dataset.py /home/abhishek/Lectures/columbia/deep_learning/project/DeepLearningImplementations/pix2pix/data/pix2pix/datasets 3 --img_size 256 --do_plot True
usage: make_dataset.py [-h] [--img_size IMG_SIZE] [--do_plot]
                       jpeg_dir nb_channels
make_dataset.py: error: unrecognized arguments: True

我在使用Bash shell。如文档中所述,我正在传递https://github.com/tdeboissiere/DeepLearningImplementations/tree/master/pix2pix/src/data
4个回答

7
根据你的配置,--do_plot选项不需要任何参数。在argparse中使用store_true参数表示只要选项存在,就会自动将True存储在相应的变量中。
因此,为了避免出现问题,只需停止向--do_plot传递True即可。

4
据我所知,您不需要指定True,只需包括--do_plot即可告诉它您想要绘图。此外,您没有配置它以接受任何参数。
在源代码的下一行中:
if args.do_plot:

如果您在命令行中实际包含了--do_plot,它将被评估为True;如果没有,则会被评估为False。

1

问题在这里的规格说明:

parser.add_argument('--do_plot', action="store_true",
                    help='Plot ...')

您已将 do_plot 声明为一个没有参数的选项;之后的 True 在您的参数协议中没有任何作用。这是一种通过省略关闭的选项,在存在时打开。


-1

只是其中一个原因(我遇到的),希望我的假设能帮助解决你的问题是,在Ubuntu上(在Windows上,不清楚但应该没问题),

当你从一个.py文件(假设叫A.py)中导入一个带有参数的函数(人们创建__main__来测试特定功能函数,称之为A函数)。导入/使用A.py可能会混淆地解析参数,因为A.py也解析参数等等。

所以,你可以通过重构代码来解决,或者只是(临时)注释掉它们先运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接