Hi,
I’m trying to load my onnx file which is transferred from Pytorch with DNN.
If I transfer the pytorch model without dynamic axes, and it goes well with cv2.dnn.readNetFromONNX. Code is shown belown.
torch.onnx.export(net, x, "test.onnx", opset_version=12, do_constant_folding=True, input_names=['input'], output_names=['output'])
dnn_net = cv2.dnn.readNetFromONNX("test.onnx")
However, when I add dynamic axes to the onnx model, DNN throws error.
dynamic_axes= {'input':{0:'batch_size'}, 'output':{0:'batch_size'}}
torch.onnx.export(net, x, "test.onnx", opset_version=12, do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=dynamic_axes)
dnn_net = cv2.dnn.readNetFromONNX("test.onnx")
Error message:
[ERROR:0] global /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1878) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Reshape]:(90)
cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1887: error: (-2:Unspecified error) in function 'handleNode'
> Node [Reshape]:(90) parse error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/core/src/matrix.cpp:250: error: (-215:Assertion failed) s >= 0 in function 'setSize'
Can anybody help? Thanks.