-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
Error loading ONNX model in opencv #8439
Comments
👋 Hello @Neskelogth, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. 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 training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available. For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com. RequirementsPython>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
@Neskelogth see Export tutorial for OpenCV DNN and C++ details. OpenCV DNN inferenceOpenCV inference with ONNX models: python export.py --weights yolov5s.pt --include onnx
python detect.py --weights yolov5s.onnx --dnn # detect
python val.py --weights yolov5s.onnx --dnn # validate C++ InferenceYOLOv5 OpenCV DNN C++ inference on exported ONNX model examples:
YOLOv5 OpenVINO C++ inference examples: YOLOv5 Tutorials
Good luck 🍀 and let us know if you have any other questions! |
I had the same problem. |
use pytorch 1.11 solved (before is 1.12 has same error) |
@msly Thanks, I'm ready to run like you said, |
solved my problem |
Before exporting or before training? |
before exporting. I tried exporting with 1.12, found this issue, downgraded, and tried detecting/training with 1.11 but it failed. Then did exporting and detecting both with 1.11 and it worked! |
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐! |
Using |
Which pytorch version ? 1.11 or 1.12, or ... 1.13 or ...? |
I just tested with opencv-python 4.6.0.66: this does NOT work, the error is the same as with the C++ test i've done. |
I got "handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs" after exporting using a colab, provided in a readme. This is a mess... |
Hello. To fix the error you must to export the PyTorch model to ONNX adding the paramter --opset 12. The complete command will look like as following:
|
@vlarobbyk thanks for sharing this solution! We appreciate your contribution to the community. 🙌 If you encounter any additional issues or have further insights, feel free to share them. |
Search before asking
YOLOv5 Component
No response
Bug
I tried to load the onnx model yolov5s.onnx on opencv after exporting it from the .pt file found in the release.
The command I used to export it is
python export.py --weights yolov5s.pt --include onnx
as seen in the instructions of the release. The problem is that if I try to load the model in opencv I get this error
[ERROR:0@14.876] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1021) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Identity]:(onnx_node!Identity_0) from domain='ai.onnx' Traceback (most recent call last): File "D:\Unitn\Corsi\Computer vision\project\synopsis\main.py", line 24, in <module> bg_frames = find_bg_frames(video, duration, fps) File "D:\Unitn\Corsi\Computer vision\project\synopsis\utils.py", line 152, in find_bg_frames people_found = find_people_with_yolo(frame) File "D:\Unitn\Corsi\Computer vision\project\synopsis\utils.py", line 102, in find_people_with_yolo net = cv2.dnn.readNet(weights) cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode' Node [Identity@ai.onnx]:(onnx_node!Identity_0) parse error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layer.cpp:246: error: (-215:Assertion failed) inputs.size() in function 'cv::dnn::dnn4_v20220524::Layer::getMemoryShapes'
While downloading a onnx file from this link the problem does not appear. I hope it's clear enough
Environment
-YOLO: YOLOv5s
-OS: Windows 10
-Python: 3.10.0
-OpenCV: 4.6.0
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: