import numpy as np
import argparse
import cv2
ap=argparse.ArgumentParser()
ap.add_argument("-i","D:\python learning\IMG_20130614_000526.jpg",required=True,help="path to input image")
ap.add_argument("-p","D:\python learning\deep-learning-face-detection\deploy.prototxt.txt",required=True,help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m","D:\python learning\deep-learning-face-detection\res10_300x300_ssd_iter_140000.caffemodel",required=True,help="path to Caffe pretrained model")
ap.add_argument("-c", "--confidence",type=float,default=0.5,help="minimum probability to filter weak detections")
args=vars(ap.parse_args())
Error:
Traceback (most recent call last):
File "D:\python learning\detectfaces.py", line 6, in <module>
ap.add_argument("-p","D:\python learning\deep-learning-face-detection\deploy.prototxt.txt",required=True,help="path to Caffe 'deploy' prototxt file")
File "C:\Users\RAJKUMAR\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1320, in add_argument
kwargs = self._get_optional_kwargs(*args, **kwargs)
File "C:\Users\RAJKUMAR\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1451, in _get_optional_kwargs
raise ValueError(msg % args)
ValueError: invalid option string 'D:\\python learning\\deep-learning-face-detection\\deploy.prototxt.txt': must start with a character '-'
>>>
It seems that the paths you are supplying (for example "D:\python learning\IMG_20130614_000526.jpg") are intended as default values for the arguments -i, -p-, -m. If that is what you are trying to do, specify them as defaults. Your code is specifying them as argument names (like --confidence) which is why argparse is telling you they must begin with a hyphen.
And if you are setting a default value for an argument, then it does not make sense also to specify required=True, because that tells argparse to insist that the user provide a value, and that defeats the object of having a default value.
For example:
ap.add_argument("-i", "--input_image", required=False, help="path to input image", default=r"D:\python learning\IMG_20130614_000526.jpg")
try this:
import numpy as np
import argparse
import cv2
ap=argparse.ArgumentParser()
ap.add_argument("-i","--input_image",required=True,help="path to input image")
ap.add_argument("-p","--deploy_file_path",required=True,help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m","--model",required=True,help="path to Caffe pretrained model")
ap.add_argument("-c", "--confidence",type=float,default=0.5,help="minimum probability to filter weak detections")
args=vars(ap.parse_args())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With