Ask Your Question

cherie's profile - activity

2020-08-24 22:08:38 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-24 21:47:16 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 20:06:50 -0600 commented question OpenCV Net from ONNX not works

Sorry for the mistake. The model export code is only for reference. I've changed it to comment.

2020-08-19 20:05:35 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 02:00:18 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:59:03 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:58:54 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:58:36 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:57:52 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:48:36 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:36:31 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:36:28 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:34:22 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:31:53 -0600 edited question OpenCV Net from ONNX not works

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

2020-08-19 01:29:33 -0600 asked a question OpenCV Net from ONNX not works

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

2020-08-19 01:29:28 -0600 asked a question OpenCV Net from ONNX not works

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

2020-08-19 01:13:40 -0600 received badge  Enthusiast
2020-08-13 21:02:44 -0600 marked best answer Importing Bidirectional LSTM model via onnx shows an error

Hi,

I'm trying to export model from easyOCR to ONNX and import it through openCV. I successfully exported it to ONNX, checked that it runs well, but failed to import the model through openCV using readNetFromONNX. Below is my model export code and the error:

batch_size=1
x = torch.rand(batch_size,1,64,256).float().cpu()
torch.onnx.export(model, (x,''), "ocr0807_0.onnx")
net = cv2.dnn.readNetFromONNX('ocr0807_0.onnx') <- where error occurs

 error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes'

The error occurs at Bidirectional LSTM layer of the model even though I'm using openCV 4.4.0 and python 3.7.

Below is the part of model code from easyOCR, which include Bidirectional LSTM:

""" Sequence modeling"""
        self.SequenceModeling = nn.Sequential(
            BidirectionalLSTM(self.FeatureExtraction_output, hidden_size, hidden_size),
            BidirectionalLSTM(hidden_size, hidden_size, hidden_size))
        self.SequenceModeling_output = hidden_size

Would you please help me with this problem? Thank you.

(NEWLY ADDED) The full error message is:

error msg is cv2.error: OpenCV(4.4.0) ../modules/dnn/src/layers/permute_layer.cpp:134: error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes'

Also, here is the error reproducing minimal test case code:

import torch.nn as nn
import torch

class BidirectionalLSTM(nn.Module):
   def __init__(self, input_size, hidden_size, output_size):
       super(BidirectionalLSTM, self).__init__()
       self.rnn = nn.LSTM(input_size, hidden_size, bidirectional=True, batch_first=True)
       self.linear = nn.Linear(hidden_size * 2, output_size)

   def forward(self, input):
       self.rnn.flatten_parameters()
       recurrent, _ = self.rnn(input)
       output = self.linear(recurrent)
       return output


class Model(nn.Module):
   def __init__(self):
       super(Model, self).__init__()
       self.SequenceModeling = nn.Sequential(
           BidirectionalLSTM(512, 512, 512),
           BidirectionalLSTM(512, 512, 512))

   def forward(self, input, text):
       contextual_feature = self.SequenceModeling(input)
       return contextual_feature


x = torch.rand(1, 65, 512).float().cpu()
model = Model()
model.eval()
torch.onnx.export(model, x, "ocr0811_1.onnx")

import cv2
net = cv2.dnn.readNetFromONNX('ocr0811_1.onnx')

Thank you.

2020-08-13 21:02:44 -0600 received badge  Scholar (source)
2020-08-13 01:02:33 -0600 received badge  Teacher (source)
2020-08-12 21:13:09 -0600 received badge  Self-Learner (source)
2020-08-12 21:06:04 -0600 edited answer Importing Bidirectional LSTM model via onnx shows an error

I uploaded this problem to issue and the bug under pull request now. https://github.com/opencv/opencv/issues/18076

2020-08-12 20:49:27 -0600 answered a question Importing Bidirectional LSTM model via onnx shows an error

I uploaded this problem to issue and the bug is fixed now. https://github.com/opencv/opencv/issues/18076

2020-08-11 03:14:02 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:09:54 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:09:10 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:08:47 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:07:19 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:05:19 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:02:29 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:01:53 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 03:00:26 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 02:59:30 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 02:58:33 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 02:56:58 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-11 02:53:06 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-10 22:29:46 -0600 commented question Importing Bidirectional LSTM model via onnx shows an error

The model construction code is same as the one in the link(https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/model

2020-08-10 02:56:12 -0600 received badge  Editor (source)
2020-08-10 02:56:12 -0600 edited question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR to ONNX and impo

2020-08-07 04:56:04 -0600 asked a question Importing Bidirectional LSTM model via onnx shows an error

Importing Bidirectional LSTM model via onnx shows an error Hi, I'm trying to export model from easyOCR(https://github.c