-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run onnx model in opencv #713
Comments
Hello @hrshovon, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , Docker Image, and Google Cloud Quickstart Guide for example environments. If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com. |
I also meet this error,have you solved this now ?or, do you have any ohter way to run the yolov5s.onnx model ?thanks |
I have not received any reply from the developer no unfortunately no. as for running model, I guess now pytorch might be the only option. |
Is there any solution? I also encountered this issue. The original code worked well with yolov3. Thanks. |
You can try on onnxruntime C++ ,I find that is ok when I use onnx1.6 and opset_version=11 to export the model.May you can refrence this sample https://github.com/microsoft/onnxruntime/blob/master/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/CXX_Api_Sample.cpp |
Thanks @zsy9512 . We finally served the onnx model using tersorrt. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Same issue. The exported file does not work. |
Same issue any solution please |
@ihmc3jn09hk @hfzarslan for running YOLOv5 in a local python project PyTorch Hub is the recommended method. See PyTorch Hub tutorial for more details: import torch
from PIL import Image
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).autoshape() # for PIL/cv2/np inputs and NMS
# Images
img1 = Image.open('zidane.jpg')
img2 = Image.open('bus.jpg')
imgs = [img1, img2] # batched list of images
# Inference
prediction = model(imgs, size=640) # includes NMS |
Hi @glenn-jocher , thank you for your suggestions. But I think the question of this thread is either
|
@ihmc3jn09hk hmm ok I see. I don't have much experience with ML models in opencv or C++, but perhaps the torchscript export is the easiest way to get a model into C? ONNX export should work also, though in its current open-source form it lacks the Detect() layer outputs, and would require additional handling that would have to be provided separately. |
@glenn-jocher I guess @hrshovon has tried on the exported ONNX which produced the errors mentioned at the top. I have tried export ONNX too and received same results. When browsing through the issue-list, I can see many others have tried with no success. Some have claimed a work-around is possible but no example is given (#1216 (@InfiniteLife)). |
same issue. any solution? |
I solve the problem, please watch my github code |
Hello @erheng-dawnlight @hpc203 , I wanted to ask what kind of FPS improvement and accuracy drops(if any) did you guys observe after the conversion and running in CPP? |
@naruarjun did you see FPS improvements? |
@hrshovon @zsy9512 @erheng-dawnlight @ihmc3jn09hk @hfzarslan @hpc203 @practical-ai @erolgerceker 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:
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 🚀! |
Any sugestion on how to use Yolov5 onnx file with opencv? Last time I checked it result in errors. |
@PauloMendes33 its very simple:
|
I understand and tested it and it runs very well. It works fine. The problem is that I am trying to read the model with OpenCV DNN module with the function |
@PauloMendes33 I would raise errors generated by external packages directly with their authors, they are outside of Ultralytics scope and control. |
❔Question
Hello all,
I trained yolov5 on my own data and created onnx model using the export script. The coreml model failed but onnx model was created successfully. But when I try to import this model in opencv(4.3.0-dev and 4.4.0-dev), I get the following error:
`cv2.error: OpenCV(4.4.0-dev) /tmp/ocv_bld/opencv/modules/dnn/src/onnx/onnx_importer.cpp:562: error: (-2:Unspecified error) in function 'void cv::dnn::dnn4_v20200609::ONNXImporter::populateNet(cv::dnn::dnn4_v20200609::Net)'
The text was updated successfully, but these errors were encountered: