进击的阿飒 2020-09-07 10:42 采纳率: 100%
浏览 322
已结题

main(sys.argv)报错:Error: too few arguments

##代码如下:##
###定义main函数并调用###

def main(argv):
    pycaffe_dir = os.path.dirname(__file__)

    parser = argparse.ArgumentParser()
    # Required arguments: input and output files.
    parser.add_argument(
        "input_file",
        help="Input image, directory, or npy."
    )
    parser.add_argument(
        "output_file",
        help="Output npy filename."
    )
    # Optional arguments.
    parser.add_argument(
        "--model_def",
        default=os.path.join(pycaffe_dir,
                             "../data/caffe_train_data/imagenet_deploy.prototxt"),
        help="Model definition file."
    )
    parser.add_argument(
        "--pretrained_model",
        default=os.path.join(pycaffe_dir,
                             "../data/caffe_train_data/caffe_reference_imagenet_model"),
        help="Trained model weights file."
    )
    parser.add_argument(
        "--gpu",
        action='store_true',
        help="Switch for gpu computation."
    )
    parser.add_argument(
        "--center_only",
        action='store_true',
        help="Switch for prediction from center crop alone instead of " +
             "averaging predictions across crops (default)."
    )
    parser.add_argument(
        "--images_dim",
        default='256,256',
        help="Canonical 'height,width' dimensions of input images."
    )
    parser.add_argument(
        "--mean_file",
        default=os.path.join(pycaffe_dir,
                             '../data/caffe_train_data/ilsvrc_2012_mean.npy'),
        help="Data set image mean of H x W x K dimensions (numpy array). " +
             "Set to '' for no mean subtraction."
    )
    parser.add_argument(
        "--input_scale",
        type=float,
        default=255,
        help="Multiply input features by this scale before input to net"
    )
    parser.add_argument(
        "--channel_swap",
        default='2,1,0',
        help="Order to permute input channels. The default converts " +
             "RGB -> BGR since BGR is the Caffe default by way of OpenCV."

    )
    parser.add_argument(
        "--ext",
        default='jpg',
        help="Image file extension to take as input when a directory " +
             "is given as the input file."
    )
    parser.add_argument(
        "--labels_file",
        default=os.path.join(pycaffe_dir,
                             "../data/caffe_train_data/synset_words_caffe_ILSVRC12.txt"),
        help="Readable label definition file."
    )
    parser.add_argument(
        "--print_results",
        action='store_true',
        help="Write output text to stdout rather than serializing to a file."
    )
    parser.add_argument(
        "--force_grayscale",
        action='store_true',
        help="Converts RGB images down to single-channel grayscale versions," +
             "useful for single-channel networks like MNIST."
    )

    parser.add_argument(
        "--run_quick_test",
        action='store_true',
        help="Switch for gpu computation."
    )

    parser.add_argument(
        "--extract_features",
        action='store_true',
        help="Switch for gpu computation."
    )

    parser.add_argument(
        "--imagelist_args",
        default='0,20',
        help="images in imglist to consider for feature computation"
    )

    args = parser.parse_args()

    if args.run_quick_test:
        runClassifierTest(args)

    if args.extract_features:
        extractFeatures(args)


if __name__ == "__main__":
    main(sys.argv)

##报错如下:
报错
###百度了一大圈,期间尝试加 nargs="?" 和改用main(sys.argv[0])解决,都不行...请各位路过的大佬救救孩子吧!
##在此xian'xing谢过!

  • 写回答

2条回答 默认 最新

  • 「已注销」 2020-09-07 15:56
    关注

    我用的python3.7 运行你这段程序没有问题图片说明图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月20日