'Converted model (from h5 to tflite) doesn't work with flutter tflite plugin

I'm new to tensorflow, I created a simple tflite model from Teachable Machine and it worked great in flutter app with tflite plugin.

Then I had to change the model with a pretrained .h5 model. I converted .h5 model to .tflite model but it crashes.

Converted pretrained model's input shape is [1, 16, 64, 64, 3](16 frame,64x64 image, 3 color) and output shape is [1, 12]. My test model's input shape is [1, 224, 224, 3] and output shape is [1, 3].

I created a .h5 model with input shape [1, 224, 224, 3] and converted it to tflite, it worked. Seems like conversion does the job and the problem may be the shape of the model. I couldn't figure out how to do it.

There is two alternative tflite plugin for flutter tflite and tflite_flutter, which one I should use and how can I do it?

Here is the code that I used for conversion.

from keras.models import load_model
model = load_model("/content/model.h5")

TF_LITE_MODEL_FILE_NAME = "model.tflite"
tf_lite_converter = tf.lite.TFLiteConverter.from_keras_model(model)
tf_lite_converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tf_lite_converter._experimental_lower_tensor_list_ops = False
tflite_model = tf_lite_converter.convert()
tflite_model_name = TF_LITE_MODEL_FILE_NAME
open(tflite_model_name, "wb").write(tflite_model)

# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
converter._experimental_lower_tensor_list_ops = False
tflite_model = converter.convert()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source