-
To convert yolov5 weights to onnx format follow this tutorial link: ultralytics/yolov5#251.
-
yolov5.onnx model in Netron
ONNXRuntime
- For GPU system install ONNXRuntime-GPU library and ONNXRuntime for CPU system.
!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:
- Input image
- Weight file
- Confidence threshold value
- IOU threshold value
- Image size
- 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:
- Input image
- Weight file
- Image width
- Image Height
- Confidence threshold value
- score threshold value
- nms threshold value
- Classes.txt file
- Comparison of inference time:
For image 'bus.jpg', inference time of ONNXRuntime and opencv DNN module are:
-
opencv DNN: 0.29987263679504395
-
ONNXRuntime: 0.13161110877990723
Streamlit yolov5 Inference App
- Install streamlit.
!pip install streamlit
- Run stramlit code.
streamlit run Streamlit_yolov5_infer.py
- References