Rewrite this code using easydict. Argparse is not working properly - python

I have the following code :
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", type=str,help="path to input image")
ap.add_argument("-east", "--east", type=str,help="path to input EAST text detector")
ap.add_argument("-c", "--min-confidence", type=float, default=0.5,help="minimum probability required to inspect a region")
ap.add_argument("-w", "--width", type=int, default=320,help="resized image width (should be multiple of 32)")
ap.add_argument("-e", "--height", type=int, default=320,help="resized image height (should be multiple of 32)")
args = vars(ap.parse_args())
The problem is that I get the following error :
usage: ipykernel_launcher.py [-h] [-i IMAGE] [-east EAST] [-c MIN_CONFIDENCE]
[-w WIDTH] [-e HEIGHT]
ipykernel_launcher.py: error: unrecognized arguments: -f C:\Users\hp\AppData\Roaming\jupyter\runtime\kernel-e147c702-ba2b-4876-a2d6-01454f32f612.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
C:\Users\hp\anaconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py:3339: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Related

I am getting 'SystemExit: 2' error , how to fix it

I am new to the machine learning coding . I am trying to run the code to find the number people in the video , image or by the live camera, but I am getting error
I am using Collab notebook to run it
'''
if __name__ == "__main__":
HOGCV = cv2.HOGDescriptor()
HOGCV.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
args = argsParser()
humanDetector(args) '''
I am getting this error
'''
usage: ipykernel_launcher.py [-h] [-v VIDEO] [-i IMAGE] [-c CAMERA]
[-o OUTPUT]
ipykernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-53a4a604-58e1-45bc-94ff-0a7c8720f3dc.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2 '''
I excepted it should run using image , video and camera in collab notebook`
You need to add in the end of " arg_parse.add_argument " line ( This is the reason you are getting 'SystemExit: 2' error ):
parser.add_argument("-f", required=False)
Edit your argsParser like this:
def argsParser():
arg_parse = argparse.ArgumentParser()
arg_parse.add_argument("-v", "--video", default='your_video_path', help="path to Video File ")
arg_parse.add_argument("-i", "--image", default='your_image_path', help="path to Image File ")
arg_parse.add_argument("-c", "--camera", default='True/False', help="Set True if you want to use the camera.")
arg_parse.add_argument("-o", "--output", type=str, default='your_output_path', help="path to optional output video file")
arg_parse.add_argument("-f", required=False)
args = vars(arg_parse.parse_args())
return args
Now you can call:
args = argsParser()
humanDetector(args)

Arg parser error :args = vars(ap.parse_args()) exception occured : 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

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

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")

Parse command line argument in python

have to do command line parsing and I am getting this error. I'm very new to Python and I don't know what the error means.
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-m", "--mask-rcnn", required=True,
help="base path to mask-rcnn directory")
ap.add_argument("-v", "--visualize", type=int, default=0,
help="whether or not we are going to visualize each instance")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
ap.add_argument("-t", "--threshold", type=float, default=0.3,
help="minimum threshold for pixel-wise mask segmentation")
args = vars(ap.parse_args())
I am getting this error:
usage: main.py [-h] -i IMAGE -m MASK_RCNN [-v VISUALIZE] [-c CONFIDENCE]
[-t THRESHOLD]
main.py: error: the following arguments are required: -i/--image, -m/--mask-rcnn
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
​
argparse processes the strings in the sys.argv list. Normally this comes from the command line values provided when calling the script containing the argparse code:
$ python main.py -i foo -m bar
But it looks like you are using ipython. It would be good to see how you call this script. But you might need to use:
$ ipython -i main.py -- -i foo -m bar
The '--' separates the input that ipython uses from the input that it should make available to main.py.

Categories