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
Related
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)
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
I have the Python script . What I'm trying to do is to test this code in colab
The problem is that the initial script requires arguments. They are defined as follows:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Pipeline to train a NN model specified by a YML config")
parser.add_argument("-t", "--tag", nargs="?", type=str, help="Model tag of the experiment", required=True)
parser.add_argument("-c", "--config", nargs="?", type=str, default="syndoc.yml", help="Config file name")
parser.add_argument("-s", "--seed", nargs="?", type=int, default=4321, help="Seed number")
parser.add_argument('-wt', '--with_test', action='store_true', help='Whether to run corresponding Tester')
args = parser.parse_args()
config = coerce_to_path_and_check_exist(CONFIGS_PATH / args.config)
run_dir = MODELS_PATH / args.tag
trainer = Trainer(config, run_dir, seed=args.seed)
trainer.run(seed=args.seed)
the error
usage: trainer.py [-h] -t [TAG] [-c [CONFIG]] [-s [SEED]] [-wt]
trainer.py: error: the following arguments are required: -t/--tag
Arguments are received when you run a program from the command line (shell, bash, cmd) and they enable effecting the program without changing it e.g. my-program -varX 1 vs my-program -varX 2, you are not doing so, so instead you can remove that code and replace args.config, args.tag etc. with variables e.g. config and tag that you define and set to the values you want.
parser = argparse.ArgumentParser(description="Pipeline to train a NN model specified by a YML config")
parser.add_argument("-t", "--tag", nargs="?", type=str, help="Model tag of the experiment", required=True)
parser.add_argument("-c", "--config", nargs="?", type=str, default="syndoc.yml", help="Config file name")
parser.add_argument("-s", "--seed", nargs="?", type=int, default=4321, help="Seed number")
parser.add_argument('-wt', '--with_test', action='store_true', help='Whether to run corresponding Tester')
args = parser.parse_args()
config = coerce_to_path_and_check_exist(CONFIGS_PATH / args.config)
run_dir = MODELS_PATH / args.tag
trainer = Trainer(config, run_dir, seed=args.seed)
trainer.run(seed=args.seed)
# 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")
I have a code in python as follows:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Experiments for optimizer')
parser.add_argument('list_experiments', type=str, nargs='+',
help='List of experiment names. E.g. CDSGD EASGD FASGD SGD Adam --> will run a training session with each optimizer')
parser.add_argument('--model_name', default='CNN', type=str,
help='Model name: CNN, Big_CNN or FCN')
parser.add_argument('--batch_size', default=128, type=int,
help='Batch size')
parser.add_argument('--nb_epoch', default=30, type=int,
help='Number of epochs')
parser.add_argument('--dataset', type=str, default="cifar10",
help='Dataset, cifar10, cifar100 or mnist')
parser.add_argument('--n_agents', default=5, type=int,
help='Number of agents')
parser.add_argument('--communication_period', default=1, type=int,
help='Gap between the communication of the agents')
parser.add_argument('--sparsity', default=False, type=bool,
help='The connection between agents if sparse or not, default: False i.e. fully connected')
args = parser.parse_args()
I wanna run it with command
python main.py CDSGD -m CNN -b 512 -ep 200 -d cifar10 -n 5 -cp 1 -s 3
but i get the following error:
main.py: error: unrecognized arguments: -m CNN -b 512 -ep 200 -d cifar10 -n 5 -cp 1 -s 3
how can i fix this problem?
A long option can be abbreviated with a unique prefix (e.g., --model will be recognized as --model_name, but short options have to be defined explicitly.
For example,
parser.add_argument('--model_name', '-m', default='CNN', type=str,
help='Model name: CNN, Big_CNN or FCN')