Convert Tensorflow LSTM model to CoreML

I have a simple tensorflow model with lstm layers. I want to convert the model to .mlmodel format. However, I think, as of now, CoreML does not support LSTM layers and hence I need to write a custom lstm layer in swift.
How can I write that custom layer?

Replies

Core ML does support LSTM layers. It appears to be the conversion from TF to Core ML that is the problem.


If you can, convert the TF model to Keras first. I've personally had success converting a Keras model with LSTM layers to Core ML.

The newer TF to CoreML converter (currently in beta) does support LSTM layers as well. To use it, there is a new flag, please see: https://github.com/tf-coreml/tf-coreml#new-beta-tfcoreml-converter-with-core-ml-3

Can you share your keras and coreml model with me? I made a next word prediction model using LSTM. I converted it to mlmodel using coremltools. The prediction results of the LSTM model and the mlmodel vary. How can I solve this issue? Thanks in advance.