-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
opencv dnn error importing onnx model: "Range" layer not supported #20324
Description
System information (version)
- OpenCV => 4.5.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2019
Detailed description
When I import an onnx model (converted from PyTorch model with Python) using "dnn::readNetFromONNX" (a SSD300_VGG16 model), an error message indicates the "Range" layer is not supported.
I previous also encountered an error: the "Sqrt" layer is not supported, but I patched it according to issue #16750
[ERROR:0] global ${OPENCV_PATH}\opencv-4.5.2\modules\dnn\src\onnx\onnx_importer.cpp (2126) cv::dnn::dnn4_v20210301::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 3 inputs and 1 outputs: [Range]:(198)
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.2) Error: Unspecified error (> Node [Range]:(198) parse error: OpenCV(4.5.2) ${OPENCV_PATH}\opencv-4.5.2\modules\dnn\src\dnn.cpp:621: error: (-2:Unspecified error) Can't create layer "198" of type "Range" in function 'cv::dnn::dnn4_v20210301::LayerData::getLayerInstance'
) in cv::dnn::dnn4_v20210301::ONNXImporter::handleNode, file ${OPENCV_PATH}\opencv-4.5.2\modules\dnn\src\onnx\onnx_importer.cpp, line 2145
Steps to reproduce
dnn::Net net = dnn::readNetFromONNX(onnx_path);Here is the onnx file link
The related layers:
%198 : Long(*, strides=[1], requires_grad=0, device=cpu) = onnx::Range(%2470, %196, %2471)
%2470 : Long(requires_grad=0, device=cpu),
%2471 : Long(requires_grad=0, device=cpu),
%196 : Long(device=cpu) = onnx::Cast[to=7](%162)
generating onnx model:
- onnx version => 1.9.0
- Pytorch version => 1.8.1
- Python version => 3.7.10
related python codes:
feat_h, feat_w = featmap_size
shift_x = torch.arange(0, feat_w, device=device) * stride[0]Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc