Open fabriziosalmi opened 1 year ago
Convert keras h5 model to Tensorflow Lite:
import tensorflow as tf
model = tf.keras.models.Sequential([ tf.keras.layers.Dense(units=1, input_shape=[1]), tf.keras.layers.Dense(units=16, activation='relu'), tf.keras.layers.Dense(units=1) ]) model.compile(optimizer='sgd', loss='mean_squared_error') # compile the model model.fit(x=[-1, 0, 1], y=[-3, -1, 1], epochs=5) # train the model
converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert()
with open('model.tflite', 'wb') as f: f.write(tflite_model)