mxochicale / Yolov5-inference-on-ONNXRuntime-and-opencv-DNN

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yolov5-inference-on-ONNXRuntime-and-Opencv-DNN

  • To convert yolov5 weights to onnx format follow this tutorial link: ultralytics/yolov5#251.

  • yolov5.onnx model in Netron

v5onnx_nms

ONNXRuntime

  • For GPU system install ONNXRuntime-GPU library and ONNXRuntime for CPU system.
!pip install -r requirements.txt

alternatively, using mamba

mamba update -n base mamba
mamba create -n yolocvVE pip -c conda-forge
mamba activate yolocvVE
pip install -r requirements.txt
  • Command to run the code:
python yolov5_onnxinfer.py  --image ./bus.jpg  --weights ./yolov5s.onnx --conf_thres 0.7 --iou_thres 0.5 --imgs 640 --classes ./classes.txt
  • Arguments Details:
  1. Input image
  2. Weight file
  3. Confidence threshold value
  4. IOU threshold value
  5. Image size
  6. Classes.txt file

Opencv DNN

  • Command to run code:
python Yolov5_infer_opencv.py --image ./bus.jpg --weights ./yolov5s.onnx --classes ./classes.txt --imgs_w 640 --imgs_h 640 --conf_thres 0.7 --score_thres 0.5 --nms_thres 0.5
  • Arguments Details:
  1. Input image
  2. Weight file
  3. Image width
  4. Image Height
  5. Confidence threshold value
  6. score threshold value
  7. nms threshold value
  8. Classes.txt file
  • Comparison of inference time: For image 'bus.jpg', inference time of ONNXRuntime and opencv DNN module are:

    1. ONNXRuntime: 0.16300702095031738
    2. opencv DNN: 0.4327085018157959

Streamlit yolov5 Inference App

  • Run stramlit code.
streamlit run Streamlit_yolov5_infer.py
  • References
  1. https://github.com/ultralytics/yolov5
  2. https://github.com/WongKinYiu/yolov7
  3. https://learnopencv.com/object-detection-using-yolov5-and-opencv-dnn-in-c-and-python/

About

License:MIT License


Languages

Language:Python 100.0%