OpenCV Net from ONNX not works
Hi,
There's an error when I try to put input to my opencv net. The net is imported onnx model, imported from pytorch model( https://github.com/sjeongab/EasyOCR/b... ). Since the model works well in pytorch and onnx form, I guess there is something wrong with net.
Link for onnx file and test image file: https://drive.google.com/drive/folder...
Below is my code:
import torch
import numpy as np
import cv2
#Input and export code for reference. Please download the onnx model from the link above
#x = torch.rand(1,1,64,256).float().cpu()
#torch.onnx.export(model, (x, ''), "ocr0814_2.onnx", keep_initializers_as_inputs=True)
net = cv2.dnn.readNetFromONNX("ocr0814_2.onnx")
img = cv2.cvtColor(cv2.imread('5.png'), cv2.COLOR_BGR2GRAY)
blob= cv2.dnn.blobFromImage(img, size=(64,256))
net.setInput(blob)
net.forward() #where the error occurs
And here is the error message:
[ERROR:0] global ../modules/dnn/src/dnn.cpp (3444) getLayerShapesRecursively OPENCV/DNN: [Reshape]:(324): getMemoryShapes() throws exception. inputs=1 outputs=1/1 blobs=0
[ERROR:0] global ../modules/dnn/src/dnn.cpp (3447) getLayerShapesRecursively input[0] = [ 1 17 512 5 ]
[ERROR:0] global ../modules/dnn/src/dnn.cpp (3451) getLayerShapesRecursively output[0] = [ ]
[ERROR:0] global ../modules/dnn/src/dnn.cpp (3457) getLayerShapesRecursively Exception message: OpenCV(4.4.0) ../modules/dnn/src/layers/reshape_layer.cpp:113: error: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'computeShapeByReshapeMask'
For your reference: The model code is scripted based on easyocr model( https://github.com/JaidedAI/EasyOCR/b... ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issu... ).
Would you please help me? Thank you.
Your code doesn't do any checking whether the function calls succeed and what the variables contain... Start with that.
Sorry for the mistake. The model export code is only for reference. I've changed it to comment.