Search code examples
pythonsystemexit

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`


Solution

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