Arg parser error :args = vars(ap.parse_args()) exception occured : python - python

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-d", "--dataset", required=True,
help="path to dataset")
ap.add_argument("-m", "--model", required=True,
help="path to Caffe pre-trained model")
ap.add_argument("-l", "--labels", required=True,
help="path to ImageNet labels (i.e., syn-sets)")
args = vars(ap.parse_args())
and I'm getting the output as
usage: train.py [-h] -i IMAGE -d DATASET -m MODEL -l LABELS
ipykernel_launcher.py: error: the following arguments are required: -i/--image, -p/--prototxt, -m/--model, -l/--labels.
An exception has occurred, use %tb to see the full traceback.
System Exit: 2

You have this error because you are running your script without passing the required parameters you defined.
You will not have the error if you run the script like this:
script_name.py -i image_path -d data_path -m model_path -l label_path

Related

While Executing code on google colab error regarding the argparse.ArgumentParser()

I am not able to solve this error is it that we cannot use argparse on google colab or there is some alternative to it
The code is:-
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--data", required=True, help="CSV file with quotes to run the model")
parser.add_argument("-m", "--model", required=True, help="Model file to load")
parser.add_argument("-b", "--bars", type=int, default=50, help="Count of bars to feed into the model")
parser.add_argument("-n", "--name", required=True, help="Name to use in output images")
parser.add_argument("--commission", type=float, default=0.1, help="Commission size in percent, default=0.1")
parser.add_argument("--conv", default=False, action="store_true", help="Use convolution model instead of FF")
args = parser.parse_args()
prices = data.load_relative(args.data)
env = environ.StocksEnv({"TEST": prices}, bars_count=args.bars, reset_on_close=False, commission=args.commission,
state_1d=args.conv, random_ofs_on_reset=False, reward_on_close=False, volumes=False)
The Error is :
usage: ipykernel_launcher.py [-h] -d DATA -m MODEL [-b BARS] -n NAME
[--commission COMMISSION] [--conv]
ipykernel_launcher.py: error: the following arguments are required: -d/--data, -m/--model, -n/--name
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2

Image manipulation dlib argparse.ArgumentParser() problem?

We are working on a project with my friend, but we still haven't gotten through a big problem. We tried many things but could not fix the problem. the problem is related to "argparse.ArgumentParser().
error part :
usage: detect_drowsiness.py [-h] -p SHAPE_PREDICTOR [-a ALARM] [-w WEBCAM]
detect_drowsiness.py: error: the following arguments are required: -p/--shape-predictor
codes part:
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,
help="path to facial landmark predictor")
ap.add_argument("-a", "--alarm", type=str, default="",
help="path alarm .WAV file")
ap.add_argument("-w", "--webcam", type=int, default=0,
help="index of webcam on system")
args = vars(ap.parse_args())
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])
file content: shape_predictor_68_face_landmarks.dat and detect_drowsiness.py(file name)
Why does this problem exist?
If you notice,
ap.add_argument("-p", "--shape-predictor", required=True,
help="path to facial landmark predictor")
-p/--shape-predictor argument is required. So, you should do the following when you run the python file:
python detect_drowsiness.py -p shape_predictor_68_face_landmarks.dat
or
python detect_drowsiness.py --shape-predictor shape_predictor_68_face_landmarks.dat

how to implement command line argument in colab?

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
help="path to input dataset")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
help="path to output loss/accuracy plot")
ap.add_argument("-m", "--model", type=str,
default="mask_detector.model",
help="path to output face mask detector model")
args = vars(ap.parse_args())
I am getting an error usage: ipykernel_launcher.py [-h] -d DATASET [-p PLOT] [-m MODEL] ipykernel_launcher.py: error: the following arguments are required: -d/--dataset An exception has occurred, use %tb to see the full traceback.
SystemExit: 2 /usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:2890: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
The declaration of the dataset argument includes required=True. If you run this script from IPython make sure to include a value for that argument. Example, assuming the script name is myscript.py and your data set is named DEFAULT_DATASET.dat:
run myscript.py -d DEFAULT_DATASET.dat
or replace the required=True argument with default="DEFAULT_DATASET.dat":
ap.add_argument("-d", "--dataset", default="DEFAULT_DATASET.dat",
help="path to input dataset")

Python Error: the following arguments are required: -p/--shape-predictor

I'm new to work with python and i want to run this code , but get this error.
code:
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True, help="path to facial landmark predictor")
ap.add_argument("-v", "--video", type=str, default="", help="path to input video file")
args = vars(ap.parse_args())
enter image description here
usage:
detect_blinks.py [-h] -p SHAPE_PREDICTOR
Error I'm Getting is:
the following arguments are required: -p/--shape-predictor
As the usage says, You need pass the necessary parameter -p/--shape-predictor.
you can just run this scripts as follows:
python detect_blinks.py -p my/path/to/predictor

How to parse arguments in python (spyder)?

I am following this tutorial and trying to run the below part of the script. I am using python 3.7 and spyder 3.3.4.
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
help="path to input dataset (i.e., directory of images)")
ap.add_argument("-m", "--model", required=True,
help="path to output model")
ap.add_argument("-l", "--labelbin", required=True,
help="path to output label binarizer")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
help="path to output accuracy/loss plot")
args = vars(ap.parse_args())
I have tried going to Run > Configuration per file and entering the arguments as advised by this post and and this post.
command line options: path1, path2, path3, path4
I filled out the appropriate paths for the arguments above and then ran the script, but go the error below.
usage: train.py [-h] -d DATASET -m MODEL -l LABELBIN [-p PLOT]
train.py: error: the following arguments are required: -d/--dataset,
-m/--model, -l/--labelbin An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
How can I fix this error to run my script appropriately and pass the arguments in spyder?
You can parse arguments by doing a special run from the settings and putting in the order that the arguments are expected.

Categories