FLming / CRNN.tf2

Convolutional Recurrent Neural Network(CRNN) for End-to-End Text Recognition - TensorFlow 2
MIT License
152 stars 56 forks source link

Load model in OpenCV #20

Closed mlaszko closed 3 years ago

mlaszko commented 3 years ago

I trained model and try to load it in OpenCV(Python).

When I convert it to frozen_graph and load:

Traceback (most recent call last):
  File "frozen_test.py", line 4, in <module>
    net = cv.dnn.readNet('frozen_graph.pb')
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1061: error: (-2:Unspecified error) Input layer not found: StatefulPartitionedCall/StatefulPartitionedCall/model/logits/Tensordot in function 'populateNet'

When I convert it to ONNX(tensorflow-onnx) and load:

  File "text_recognition.py", line 32, in loadRecognitionModel
    self.recognizer = cv.dnn.readNet(modelRecognition)
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1887: error: (-2:Unspecified error) in function 'handleNode'
> Node [Gather]:(StatefulPartitionedCall/model/reshape7/Shape:0) parse error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1648: error: (-215:Assertion failed) indexMat.total() == 1 in function 'handleNode'

Python 3.8.5 Tensorflow 2.5.0 OpenCV 4.5.1 Ubuntu 20.04.2 LTS

What is the best way to use CRNN.tf2 in OpenCV?

FLming commented 3 years ago

Sorry, I don't know. As far as I know, OpenCV only support TF1 model. But I just looked through the document, it seems added support for TF2, maybe you can follow the tutorial.

FLming commented 3 years ago

I will also try to convert next working day, I hope it works.

FLming commented 3 years ago

It seems that there are still many things that cannot be achieved. If there is new progress, I will reopen this issue.