0

I trained a custom YOLOv7 object detection model in Google Colab. I exported it to .onnx file using this command: python export.py --weights runs/train/exp/weights/best.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.3 --img-size 640 640 --max-wh 640

This is my code to load the model:

import cv2

net = cv2.dnn.readNet('runs/train/exp/weights/best.onnx')

When I run the code above, I get this error:

error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode'
> Node [NonMaxSuppression@ai.onnx]:(onnx_node!NonMaxSuppression_370) parse error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/layer_internals.hpp:110: error: (-2:Unspecified error) Can't create layer "onnx_node!NonMaxSuppression_370" of type "NonMaxSuppression" in function 'getLayerInstance'

However, this python code loads the model successfully:

import onnx
onnx_model = onnx.load('runs/train/exp/weights/best.onnx')
onnx.checker.check_model(onnx_model)

So seems like the issue is in OpenCV?

The .onnx file is in the correct directory.

Enviroment:

opencv-python: 4.6.0.66
torch: 1.11.0
onnx: 1.11.0
CUDA: 11.2

My PyTorch was previously version 1.12.0, but I got similar issues too. Then I read somewhere that downgrading to 1.11.0 should fix my problem. It didn't.

I downloaded a pre-exported .onnx file from google and it loaded successfully using the same code. Why can't I do it now?

ZawaXXD
  • 1
  • 1
  • did you search and find this one? https://stackoverflow.com/questions/73713400/yolov7-using-opencv-4-6-0-dnn maybe you can find out what happened to the pull request – Micka Jan 23 '23 at 14:51

0 Answers0