Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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'

Would you please help me? Thank you.

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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'

Would you please help me? Thank you.

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

Would you please help me? Thank you.

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

Would you please help me? Thank you.

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

Would you please help me? Thank you.

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, converted from pytorch model of easyocr(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). easyocr (https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Since, Bidirectional LSTM model of easyocr made error with opencv 4.4, I changed module code of Bidirectional LSTM model to the code commented in this issue: https://github.com/opencv/opencv/issues/18076

So the final module code will be like this: https://github.com/sjeongab/EasyOCR/blob/master/easyocr/modules.py

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

Would you please help me? Thank you.

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, converted imported from pytorch model of easyocr (https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py). model( https://github.com/sjeongab/EasyOCR/blob/master/easyocr/model.py ). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Since, Bidirectional LSTM model of easyocr made error with opencv 4.4, I changed module code of Bidirectional LSTM model to the code commented in this issue: https://github.com/opencv/opencv/issues/18076

So the final module code will be like this: https://github.com/sjeongab/EasyOCR/blob/master/easyocr/modules.py

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

The model code is scripted based on easyocr model( https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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'

The model code is scripted based on easyocr model( https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). Since the model works well in pytorch and onnx form, I guess there is something wrong with net. Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). 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/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

Below is my code:

import torch
import numpy as np
import cv2

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

Link for onnx file and test image file: https://drive.google.com/drive/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). 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/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

Below is my code:

import torch
import numpy as np
import cv2

x #x = torch.rand(1,1,64,256).float().cpu()
torch.onnx.export(model, #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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). 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/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

Below is my code:

import torch
import numpy as np
import cv2

#Model 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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.

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/blob/master/easyocr/model.py ). 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/folders/16qZIb6hgb2Ope4rSIA2QB_QS1NJPXbBK?usp=sharing

Below is my code:

import torch
import numpy as np
import cv2

#Model input #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/blob/master/easyocr/model.py ), with Bidirectional LSTM module code changed as commented in this issue( https://github.com/opencv/opencv/issues/18076 ).

Would you please help me? Thank you.