alanswx / keras_to_tensorflow

Convert keras models to tensorflow frozen graph for use on cell phones, etc
MIT License
21 stars 14 forks source link

failed to convert Keras LSTM layer to freeze graph #1

Open hozen opened 6 years ago

hozen commented 6 years ago

The Keras backend is Tensorflow, and the model comes from Keras example: https://github.com/keras-team/keras/blob/master/examples/imdb_lstm.py

I am trying to convert Keras model (.h5) to freeze graph (.pb), and then convert to tflite (*.tflite). Not directly convert Keras to tflite is because the tool tflite_convert get failed (lack of bias parameters). I checked with all dense layer model, this approach works well. But now get failed when handle rnn model.

The Keras model I've built is viewed as below: image

After run convertkeras.py, the generated pb file .pb doesn't contain any LSTM layer, but only with the first Embedding layer and the last dense layer, and a huge expanded networks (i guess): image

Do you know why this happened? I've also checked one of the official tflite model (speech_speakerid_model_2017_11_14.tflite), it indeed contains LSTM layer, that means freeze graph or tflite should support this layer type: image

alanswx commented 6 years ago

I am not sure why it isn’t working. Let me know if you figure it out and if we should patch the script.