TensorSpeech / TensorFlowASR

:zap: TensorFlowASR: Almost State-of-the-art Automatic Speech Recognition in Tensorflow 2. Supported languages that can use characters or subwords
https://huylenguyen.com/asr
Apache License 2.0
924 stars 243 forks source link

ConverterError:input resource[0] expected type resource !=float, the type of contextnet_greedy_while_contextnet_decoder_contextnet_prediction_embedding_embedding_lookup_24797_0[0] #236

Open MhmudAlpurd opened 2 years ago

MhmudAlpurd commented 2 years ago

Hi everyone, I'm going to convert h5 to tflite of contexnet model, by executing tflite.py in the examples/contextnet/ direction, and I get several errors. I run these commands in order, git clone https://github.com/TensorSpeech/TensorFlowASR.git \n cd TensorFlowASR \n pip3 install -e ".[tf2.x]" # or ".[tf2.x-gpu]" \n pip3 install -U "TensorFlowASR[tf2.x]" \n error occurs: File "tflite.py", line 65, in <module> tflite_model = converter.convert() File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 1682, in convert return super(TFLiteConverterV2, self).convert() File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 782, in wrapper return self._convert_and_export_metrics(convert_func, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 768, in _convert_and_export_metrics result = convert_func(self, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 1352, in convert self).convert(graph_def, input_tensors, output_tensors) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 956, in convert **converter_kwargs) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/convert_phase.py", line 213, in wrapper raise converter_error from None # Re-throws the exception. File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/convert_phase.py", line 206, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/convert.py", line 828, in toco_convert_impl enable_mlir_converter=enable_mlir_converter) File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/convert.py", line 311, in toco_convert_protos

raise converter_error tensorflow.lite.python.convert_phase.ConverterError: input resource[0] expected type resource != float, the type of contextnet_greedy_while_contextnet_decoder_contextnet_prediction_embedding_embedding_lookup_24797_0[0] In {{node contextnet_greedy/while/contextnet_decoder/contextnet_prediction_embedding/embedding_lookup}} Failed to functionalize Control Flow V1 ops. Consider using Control Flow V2 ops instead. See https://www.tensorflow.org/api_docs/python/tf/compat/v1/enable_control_flow_v2. then I execute tflite conversion codes that come to the ReadMe.md. but I do not succeed until now. How can I convert transducer or contextnet h5 models to tflite, directly?

liuyibox commented 1 year ago

Any updated solution here? I encountered the same issue here with tf2.9.

liuyibox commented 1 year ago

This bug has been resolved https://github.com/tensorflow/tensorflow/issues/42410#issuecomment-1201150119. Basically, we just need to load model while are are loading the concrete function, i.e., change this line to converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func], model).