-2
opencv
module_error
ai_generated
partial
cv2.error: OpenCV(4.8.0) /tmp/opencv-4.8.0/modules/dnn/src/onnx/onnx_importer.cpp:203: error: (-2:未指定错误) 无法解析 ONNX 模型:在域版本 12 中未注册 'NonMaxSuppression' 操作 在函数 'readNetFromONNX' 中
cv2.error: OpenCV(4.8.0) /tmp/opencv-4.8.0/modules/dnn/src/onnx/onnx_importer.cpp:203: error: (-2:Unspecified error) Failed to parse ONNX model: No Op registered for 'NonMaxSuppression' with domain_version of 12 in function 'readNetFromONNX'
ID: opencv/dnn-readnet-from-onnx-parse-error
80%修复率
88%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
| 4.10.0 | active | — | — | — |
根因分析
ONNX 模型使用了 OpenCV DNN 模块在给定操作集版本中不支持的操作符(例如 NonMaxSuppression)。
English
ONNX model uses an operator (e.g., NonMaxSuppression) that is not supported by the OpenCV DNN module for the given opset version.
官方文档
https://docs.opencv.org/4.x/d6/d0f/group__dnn.html#ga29f34df9376379a603acd8df581ac8d7解决方案
-
Export the ONNX model with a lower opset version (e.g., 11) that includes all operators supported by OpenCV: `torch.onnx.export(model, dummy_input, 'model.onnx', opset_version=11)`
-
Use OpenCV's DNN with a different backend like Intel OpenVINO: `net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)`
-
Convert the ONNX model to a different format (e.g., TensorFlow SavedModel) and load with OpenCV's TensorFlow importer.
无效尝试
常见但无效的做法:
-
60% 失败
Downgrading OpenCV may remove support for newer ONNX opsets but won't add missing operators.
-
80% 失败
ONNX Runtime is a separate inference engine; installing it doesn't modify OpenCV's DNN module.
-
90% 失败
Changing the model file name or path doesn't affect operator parsing.