qq_36235935
进击的程序媛阿飒
2020-09-07 10:42

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

  • python
  • 机器学习
  • 深度学习
  • 人工智能

##代码如下:##
###定义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谢过!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐