Sunday 3 January 2021

Forward method error in dnn module of open cv, (ptyhon) using .onnx model

I wanted to test a pretrained model downlaoaded from here to perform an ocr task. Link to download: https://drive.google.com/drive/folders/1cTbQ3nuZG , its name is CRNN_VGG_BiLSTM_CTC.onnx. This model is extracted from https://docs.opencv.org/master/d9/d1e/tutorial_dnn_OCR.html. The sample-image.png can be download from https://i.ibb.co/fMmCB7J/sample-image.png (see the code bellow).

When I do the forward of the neural network to predict (ocr) in the blob I get the following error:

 error: OpenCV(4.4.0) /tmp/pip-req-build-xgme2194/opencv/modules/dnn/src/layers/convolution_layer.cpp:348: error: (-215:Assertion failed) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function 'getMemoryShapes'
 

Feel free to read the code bellow. I tried many things, it's weird because this model does not require a predetermined input shape. If you know any way to read this model and do the forward it is also going to be helpful but I 'd rather solve using opencv.

import cv2 as cv
# The model is downloaded from here https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr
# model path 
modelRecognition = os.path.join(MODELS_PATH,'CRNN_VGG_BiLSTM_CTC.onnx')
# read net 
recognizer = cv.dnn.readNetFromONNX(modelRecognition)

# Download sample_image.png from https://i.ibb.co/fMmCB7J/sample-image.png  (image host website)
sample_image = cv.imread('sample-image.png')
# Height , Width and number of channels of the image
H,W,C = sample_image.shape

# Create a 4D blob from cropped image
blob = cv.dnn.blobFromImage(sample_image, size=(H,W))

recognizer.setInput(blob)

Thank you so much in advance.



from Forward method error in dnn module of open cv, (ptyhon) using .onnx model

No comments:

Post a Comment