From 5983f5ce6f421855ecf62e0a680f364dd4a77a56 Mon Sep 17 00:00:00 2001 From: Hamza TOUIZRAT Date: Sun, 5 Jul 2026 16:08:54 +0000 Subject: [PATCH] fix: Use Keras native format (.keras) for model serialization The previous TensorFlow SavedModel format was failing in certain environments. This change switches to the Keras native format (.keras) which is more stable and is the recommended approach for saving Keras models. Changes: - Use model.save() with .keras extension instead of SavedModel format - Create output directory if it doesn't exist - Update log message to reflect new file path This fixes issues with model serialization in the hello_world example. --- tensorflow/lite/micro/examples/hello_world/train.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tensorflow/lite/micro/examples/hello_world/train.py b/tensorflow/lite/micro/examples/hello_world/train.py index 59483acf04a..18650e549ea 100644 --- a/tensorflow/lite/micro/examples/hello_world/train.py +++ b/tensorflow/lite/micro/examples/hello_world/train.py @@ -120,8 +120,11 @@ def train_model(epochs, x_values, y_values): verbose=2) if FLAGS.save_tf_model: - model.save(FLAGS.save_dir, save_format="tf") - logging.info("TF model saved to %s", FLAGS.save_dir) + save_path = os.path.join(FLAGS.save_dir, "model.keras") + if not os.path.exists(FLAGS.save_dir): + os.makedirs(FLAGS.save_dir) + model.save(save_path) + logging.info("TF model saved to %s", save_path) return model