Skip to content

Instantly share code, notes, and snippets.

@SmiffyKMc
Created June 17, 2022 20:30
Show Gist options
  • Save SmiffyKMc/43e6b3c1539178c9520084be928ce055 to your computer and use it in GitHub Desktop.
Save SmiffyKMc/43e6b3c1539178c9520084be928ce055 to your computer and use it in GitHub Desktop.
Converting model to Tensorflow Lite
from tensorflow import keras
import pathlib
test_model = keras.models.load_model(f"{hotDogDir}hotdog_classifier_v4.keras")
converter = tensorflow.lite.TFLiteConverter.from_keras_model(test_model)
tflite_model = converter.convert()
tflite_models_dir = pathlib.Path(f"{hotDogDir}")
tflite_models_dir.mkdir(exist_ok=True, parents=True)
tflite_model_file = tflite_models_dir/"hotdog_classifier.tflite"
tflite_model_file.write_bytes(tflite_model)
converter.optimizations = [tensorflow.lite.Optimize.DEFAULT]
tflite_quant_model = converter.convert()
tflite_model_quant_file = tflite_models_dir/"hotdog_classifier.tflite"
tflite_model_quant_file.write_bytes(tflite_quant_model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment