Python 无法识别的参数:True
代码: 错误:Python 无法识别的参数:True,python,Python,代码: 错误: 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 cha
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()
我在这里使用的是bashshell。正如文档中所提到的,我正在通过,就我所知,您不需要指出True,只要包括
--do_plot
,它就告诉它您想要进行plot。另外,您没有将其配置为接受任何参数
在源代码的以下行中:
$ 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
如果您在命令行中实际包含了
--do_plot
,它将被评估为True,如果没有,它将被评估为False。据我所知,您不需要指示True,只要包含--do_plot
,它就告诉它您想要进行plot。另外,您没有将其配置为接受任何参数
在源代码的以下行中:
$ 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
如果您在命令行中实际包含了
--do_plot
,它将被计算为True,如果没有,它将被计算为False。在您配置它时,--do_plot
选项不带任何参数。argparse
中的store\u true
参数表示该选项的存在将自动将true
存储在相应的变量中
因此,为了防止出现问题,只需停止将
True
传递到——do_plot
配置后,--do_plot
选项不接受任何参数。argparse
中的store\u true
参数表示该选项的存在将自动将true
存储在相应的变量中
因此,为了防止出现问题,只需停止将
True
传递到——do_plot
这里的规范中有问题:
if args.do_plot:
您已将do_plot声明为无参数的选项;之后的True在您的参数协议中没有任何意义。这是一个因省略而关闭的选项,存在时打开。此处的规范中有问题:
if args.do_plot:
您已将do_plot声明为无参数的选项;之后的True在您的参数协议中没有任何意义。这是一个因遗漏而关闭的选项,在出现时打开。这只是原因之一(我所面对的),希望我的假设能帮助解决你的问题,那就是在Ubuntu上(在Windows上,IDK上,但没问题)
当您从包含参数的.py
文件(比如a.py
)导入函数时(人们创建\uuuu main\uuuu
来测试功能函数,让我们调用a
函数)。.py
导入/使用A
可能会混淆解析参数,因为A.py
也解析参数等等
所以,你可以通过重构来解决问题,或者只是(暂时)把它们注释出来,让它们先运行。这只是原因之一(我面临的),希望我的假设能帮助你解决这个问题,那就是在Ubuntu上(在Windows上,IDK上,但没问题)
当您从包含参数的.py
文件(比如a.py
)导入函数时(人们创建\uuuu main\uuuu
来测试功能函数,让我们调用a
函数)。.py
导入/使用A
可能会混淆解析参数,因为A.py
也解析参数等等
所以,您可以通过重构来解决问题,或者(暂时)将它们注释出来,以便首先运行