I have a tensorsorflow lite model (keras) in a flutter application that segments objects in an image (model is trained only on one specific object). With this model I can make 50-60 predictions without problems. Now i used the exact same model to train for another classification, when i use these two in a sequence it crashes after 3 images because of a memory leakage. For this task i have to have separate models, because in the future i might want to add/remove/switch just some of the models.
Does anyone have experience with keras.tenorsflow and memory leakage when tflite models are run sequentially?
I have done:
- both models to tflite
- include optimizers as false
- compile as false
What i can not figure out:
- Why one model can make 60 predictions in a row but not more than 3 when 2 models are run
- How i can clear memory in flutter application
- Where in model.predict() memory leakage occur
And i tried to minimize the size of the models through code below but that did not solve the issue.
import tensorflow as tf
model = tf.keras.models.load_model("model")
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
converter.target_spec.supported_types = [tf.float16]
tflite_quant_model = converter.convert()
#save converted quantization model to tflite format
open("model.tflite", "wb").write(tflite_quant_model)