2017-04-13 175 views
0

代碼:無法識別的參數:真

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

回答

1

就我所知,只要包含--do_plot,就不需要指出True,它告訴它你想要做陰謀。另外,你沒有配置它來接受任何參數。

在下面一行的源代碼:

if args.do_plot: 

如果你確實包含在命令行--do_plot,它將被評估爲true,如果不是,它將作爲虛假評估。

1

正如您所配置的那樣,--do_plot選項不帶任何參數。​​中的一個store_true參數表示選項的存在會自動將True存儲在相應的變量中。

因此,爲了防止您的問題,只是停止通過True--do_plot

0

的問題是在規範這裏:

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

您已經聲明do_plot作爲不帶參數的選項;之後的True在您的參數協議中沒有任何用處。這是一個選項,由於遺漏而關閉,如果有的話。