FLming / CRNN.tf2

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

tflite-converter.py problem #15

Closed nosun10005 closed 3 years ago

nosun10005 commented 3 years ago

I'm learning a lot from this project. Thank you.

I'm testing with the h5 file you put on Google Drive. However, the following error occurs.

python : 3.7.0 tensorlfow version : 2.4.0

1. export.py ==> Success

/opt/miniconda3/envs/crnn/bin/python /Users/nosun10005/PycharmProjects/CRNN.tf2-master/tools/export.py --model ../example/model/exported_model.h5 --output ../example/model/saved --config ../configs/mjsynth.yml --post greedy

2. tflite-converter.py ==> Fail

/opt/miniconda3/envs/crnn/bin/python /Users/nosun10005/PycharmProjects/CRNN.tf2-master/tools/tflite_converter.py -m ../example/model/saved -o ../example/model/exported_model.tflite ....... function_optimizer: Graph size after: 752 nodes (709), 959 edges (915), time = 44.655ms. function_optimizer: Graph size after: 752 nodes (0), 959 edges (0), time = 18.138ms. Optimization results for grappler item: inference_while_cond_5605_592 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0.001ms. Optimization results for grappler item: inference_model_ctc_greedy_decoder_RaggedFromSparse_Assert_AssertGuard_true_6516_30714 function_optimizer: function_optimizer did nothing. time = 0ms. function_optimizer: function_optimizer did nothing. time = 0.001ms. Optimization results for grappler item: inference_while_cond_4719_5412 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0ms. Optimization results for grappler item: inference_while_body_5606_37121 function_optimizer: function_optimizer did nothing. time = 0ms. function_optimizer: function_optimizer did nothing. time = 0ms. Optimization results for grappler item: inference_while_body_6046_31456 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0ms. Optimization results for grappler item: inference_while_body_5160_7831 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0ms. Optimization results for grappler item: inference_while_cond_6045_40507 function_optimizer: function_optimizer did nothing. time = 0ms. function_optimizer: function_optimizer did nothing. time = 0.001ms. Optimization results for grappler item: inference_while_cond_5159_3281 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0.001ms. Optimization results for grappler item: inference_model_ctc_greedy_decoder_RaggedFromSparse_Assert_AssertGuard_false_6517_4821 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0.001ms. Optimization results for grappler item: inference_while_body_4720_763 function_optimizer: function_optimizer did nothing. time = 0.001ms. function_optimizer: function_optimizer did nothing. time = 0ms.

Traceback (most recent call last): File "/Users/nosun10005/PycharmProjects/CRNN.tf2-master/tools/tflite_converter.py", line 22, in tflite_model = converter.convert() File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/lite/python/lite.py", line 1117, in convert return super(TFLiteConverterV2, self).convert() File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/lite/python/lite.py", line 920, in convert _convert_to_constants.convert_variables_to_constants_v2_as_graph( File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1102, in convert_variables_to_constants_v2_as_graph converter_data = _FunctionConverterData( File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py", line 806, in init self._build_tensor_data() File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py", line 825, in _build_tensor_data data = val_tensor.numpy() File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 1071, in numpy maybe_arr = self._numpy() # pylint: disable=protected-access File "/opt/miniconda3/envs/crnn/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 1039, in _numpy six.raise_from(core._status_to_exception(e.code, e.message), None) # pylint: disable=protected-access File "", line 3, in raise_from tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot convert a Tensor of dtype resource to a NumPy array.

FLming commented 3 years ago

Sorry, now, the model added decoder post-process can't convert to the TFlite model, but without the decoder, it's fine.

FLming commented 3 years ago

I am exploring how to convert the model with the decoding process into the TFlite model. StringLookup layer can't convert to the TFlite, wait for the official update, or explore the implementation method...

nosun10005 commented 3 years ago

Thank you for your prompt reply. I'll check the code.