0

https://github.com/ITCoders/Human-detection-and-Tracking/blob/master/main.py This is the code I obtained for the human detection. I'm using anaconda navigator(jupyter notebook). How can I use argument parser in this? How can I give the video path -v ? Can anyone please say me a solution for this? As the running of the program is done by clicking on the run button or by giving shift+Enter. I need to do human detection. I'm a beginner to python and opencv. So please do help.

van neilsen
  • 547
  • 8
  • 21
Ruksin Kamal
  • 25
  • 1
  • 1
  • 4
  • You should put your code here, as part of your question, and provide a minimal; reproductible example of your issue – ted Jun 26 '18 at 09:26
  • I would just create a new Jupyter cell where I'd define the values I'd give as arguments. You can put those values in the `args` dict directly, and then call whatever function uses it. – Glrs Jun 26 '18 at 12:29
  • Possible duplicate of [Passing command line arguments to argv in jupyter/ipython notebook](https://stackoverflow.com/questions/37534440/passing-command-line-arguments-to-argv-in-jupyter-ipython-notebook) – pragmaticprog Jun 27 '18 at 12:02

3 Answers3

13

All for me to do was pass an empty string to parser.parse_args()

parser.parse_args() > parser.parse_args("")

And that was all for me.

Tillmann2018
  • 327
  • 5
  • 10
2

What you are asking seems similar to: Passing command line arguments to argv in jupyter/ipython notebook

There are two different methods mentioned in the post that were helpful. That said, I would suggest using command line tools and a Python IDE for writing scripts to run machine learning models. IPython may be helpful for visualization, fast debugging or running pre-trained models on commonly available datasets.

pragmaticprog
  • 550
  • 2
  • 15
2

I tried out the answers listed on "Passing command line arguments to argv in jupyter/ipython notebook", and came up with a different solution.

My original code was

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
ap.add_argument("-y", "--yolo", required=True, help="base path to YOLO directory")
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="threshold when applying non-maxima suppression")
args = vars(ap.parse_args())

The most common solution was to create a dummy class, which I wrote as:

Class Args():
    image='photo.jpg'
    yolo='yolo-coco'
    confidence=0.5
    threshold=0.3

args=Args()

but futher code snippets were producing an error.

So I printed args after vars(ap.parse_args()) and found that it was a dictionary.

So just create a dictionary for the original args:

args={"image":  'photo.jpg', "yolo":  'yolo-coco', "confidence": 0.5,"threshold": 0.3}
RugsB3
  • 41
  • 1