Memory Leakage tflite models

Viewed 243

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:

  1. both models to tflite
  2. include optimizers as false
  3. compile as false

What i can not figure out:

  1. Why one model can make 60 predictions in a row but not more than 3 when 2 models are run
  2. How i can clear memory in flutter application
  3. 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)
0 Answers
Related