TensorSpeech / TensorFlowTTS

:stuck_out_tongue_closed_eyes: TensorFlowTTS: Real-Time State-of-the-art Speech Synthesis for Tensorflow 2 (supported including English, French, Korean, Chinese, German and Easy to adapt for other languages)
https://tensorspeech.github.io/TensorFlowTTS/
Apache License 2.0
3.8k stars 810 forks source link

Runtime error in Android when running inference on Tflite #715

Closed ihshareef closed 2 years ago

ihshareef commented 2 years ago

I've trained FastSpeech 2 successfully, and it works as expected on Python. However, when I converted it to TFLITE and deployed it on Android, I'm getting the following run-time error.

    java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: tensorflow/lite/kernels/reshape.cc:58 stretch_dim != -1 (0 != -1)
    Node number 83 (RESHAPE) failed to prepare.

I was able to run the whole pipeline successfully earlier this year. Since I used Google Colab for the training, I ended up using tensorflow-gpu==2.4.1 for the training. I attempted doing the Tflite conversion using 2.3.1, and even though I was able to run the inference perfectly on Python: it kept failing on Android.

Should I retrain the FastSpeech2 model and then convert? What can I do to solve the problem?

dathudeptrai commented 2 years ago

@ihshareef I think a bug comes from TFLite, you should ask a TensorFlow repo for this problem. TFlite always make a new bug in a new version :)))

ihshareef commented 2 years ago

I managed to fix the problem. I retrained FastSpeech2 on Tensorflow 2.3.1 and used the Colab notebook associated with this repo to convert it to Tflite. It worked perfectly on Android, unlike before. So, as far as I can tell--models trained on Tensorflow 2.3.1 can be used stably with Android. I'm just leaving this comment here so that others may benefit. The only reason I ended up working with Tensorflow 2.4.1 was because Google Colab started giving me the following error: ImportError: cannot import name 'LayerNormalization'

This arose because of a conflict within Google Colab (which comes with Tensorflow 2.7.0 installed). The trick is to uninstall the existing installation and reinstall you desired version (2.3.1 in my case) -- check this answer on Stack Overflow.