Created
December 20, 2020 19:25
-
-
Save deepak-karkala/a125c1a8b21296172cfa5c95f6fbc792 to your computer and use it in GitHub Desktop.
Model quantisation using TFLite
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
# Model quantisation using TFLite | |
save_model_path = "/tmp/" | |
# Save original model in tflite format | |
tflite_models_dir = pathlib.Path(save_model_path) | |
tflite_models_dir.mkdir(exist_ok=True, parents=True) | |
converter = tf.lite.TFLiteConverter.from_keras_model(model) | |
tflite_model = converter.convert() | |
tflite_model_file = tflite_models_dir/"model.tflite" | |
print(tflite_model_file.write_bytes(tflite_model)) | |
# Save quantized model in tflite format | |
converter.optimizations = [tf.lite.Optimize.DEFAULT] | |
converter.target_spec.supported_types = [tf.float16] | |
tflite_fp16_model = converter.convert() | |
tflite_model_fp16_file = tflite_models_dir/"model_quant_f16.tflite" | |
print(tflite_model_fp16_file.write_bytes(tflite_fp16_model)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment