Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert YOLOv5 PyTorch model to OpenCV DNN compatible format

Could anybody please help me to convert YOLOv5 PyTorch model to ONNX or TensorFlow format to be able to use it with OpenCV C++ inference?

I used this tutorial to train the model with colab: https://blog.roboflow.com/how-to-train-yolov5-on-a-custom-dataset/

Maybe there is a way of conversion in colab or I should use any other tools?

like image 577
al072 Avatar asked Nov 24 '25 07:11

al072


1 Answers

Below is the recent reply from ultralytics developers(YoloV5 creators) regarding OpenCV & YoloV5 compatibility. In fact I'm also looking for correct implementation tutorial.

👉 Original Thread

Good news 😃! Your original issue may now be fixed ✅ in PR #4833 by @SamFC10. This PR implements architecture updates to allow for ONNX-exported YOLOv5 models to be used with OpenCV DNN.

To receive this update:

  • Git – git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle. Colab
  • Docker – sudo docker pull ultralytics/yolov5:latest to update your image.

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

like image 187
snehit vaddi Avatar answered Nov 26 '25 23:11

snehit vaddi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!