I am new to Flutter development and have been using Teachable Machine to create my models and connect them to my Flutter app using the flutter_tflite: ^1.0.1 dependency. When I export a model from Teachable Machine, I receive a .tflite file and a label.txt file. The conversion model is in floating-point format.
Now, I have created my own model in Jupyter Notebook. How can I achieve the same—converting my model to a .tflite file and obtaining a label.txt file where the conversion model is in floating-point format?
I’ve tried converting the model to TensorFlow Lite using this code, but I’m getting a .tflite model without the labels.txt file. Additionally, I’m not sure if the conversion model is in floating-point format.using this code
import tensorflow as tf
import tensorflow.lite as tflite
import os
Path to the directory containing the saved model
saved_model_dir = “C:UsersPCDesktopmodels2”
try:
# Load the model
converter = tflite.TFLiteConverter.from_saved_model(saved_model_dir)
print(“Model loaded successfully.”)
# Convert the model to TensorFlow Lite format
tflite_model = converter.convert()
print("Model converted successfully.")
# Specify the output directory and file name
output_dir = "C:\Users\PC\Desktop\models\converted"
os.makedirs(output_dir, exist_ok=True)
output_file = os.path.join(output_dir, "converted_model.tflite")
# Save the converted model to a file
with open(output_file, "wb") as f:
f.write(tflite_model)
print(f"Model saved successfully as {output_file}.")
except Exception as e:
print(f”An error occurred: {e}”)