Created
June 17, 2022 20:30
-
-
Save SmiffyKMc/43e6b3c1539178c9520084be928ce055 to your computer and use it in GitHub Desktop.
Converting model to Tensorflow Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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