Local Inference with YOLOv5 on a Webcam
- Make a note of the directory (folder) in which you clone the repository. Save the file path, if you can, for easy access later.
- GitHub commands cheatsheet
Include the model weights in the "yolov5" folder that was cloned to your file system (computer) from GitHub.
Running the Webcam Model
Once the custom weights have been added to the yolov5 directory on your local computer, then you can run the model in your webcam after changing to the yolov5 directory in your terminal.
Basic Command: Run YOLOv5 on a Webcam
As the "yolov5" directory in the example image resides in the "mtraor3" directory, and we are using the yolov5s model weights saved to the yolov5 folder ( /Users/mtraor3/yolov5 ), the sample code we enter in our terminal to run locally on the webcam would look like this:
python ./Users/mtraor3/yolov5/detect.py --weights ./Users/mtraor3/yolov5/yolov5s.pt --save_text --save_conf --conf-thres 0.40 --source 0
Saving predictions and confidence scores to a .txt-file with inference performed at a confidence threshold of 40%
python path/to/detect.py --weights /path/to/modelweights.pt --save_text --save_conf --conf-thres 0.40 --source 0
If the model weights file were titled "my_custom_weights.pt" then the code becomes:
python ./Users/mtraor3/yolov5/detect.py --weights ./Users/mtraor3/yolov5/my_custom_weights.pt --save_text --save_conf --conf-thres 0.40 --source 0
There are more optional arguments for doing things like changing the confidence threshold, saving cropped prediction boxes, etc.
Saving the predictions and confidence scores to a .txt-file, with inference at a confidence threshold of 40%.