Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save converted model locally. #77

Open
Kheertik opened this issue Jul 10, 2024 · 0 comments
Open

Unable to save converted model locally. #77

Kheertik opened this issue Jul 10, 2024 · 0 comments

Comments

@Kheertik
Copy link

Hello, I used the code and was able to train a model. When I converted the model from h5 to tflite, it didn't save, and I cannot find it anywhere.

`from tensorflow.keras.models import load_model
from kapre.time_frequency import STFT, Magnitude, ApplyFilterbank, MagnitudeToDecibel
import tensorflow as tf

Load the Keras model

model_path = r'models\lstm.h5' # Using a raw string for Windows path
keras_model = tf.keras.models.load_model(model_path, custom_objects={
'STFT': STFT,
'Magnitude': Magnitude,
'ApplyFilterbank': ApplyFilterbank,
'MagnitudeToDecibel': MagnitudeToDecibel
})

Convert the model to TFLite

converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
tflite_model = converter.convert()

Save the converted model to a .tflite file

tflite_path = r'\models\model.tflite'
with open(tflite_path, 'wb') as f:
f.write(tflite_model)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant