Skip to content

Instantly share code, notes, and snippets.

@AkiyonKS
Created August 9, 2022 05:14
Show Gist options
  • Save AkiyonKS/dfaefed629c92e0562397be53074f28a to your computer and use it in GitHub Desktop.
Save AkiyonKS/dfaefed629c92e0562397be53074f28a to your computer and use it in GitHub Desktop.
converter = tf.lite.TFLiteConverter.from_keras_model(model_for_export)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
quantized_and_pruned_tflite_model = converter.convert()
_, quantized_and_pruned_tflite_file = tempfile.mkstemp('.tflite')
with open(quantized_and_pruned_tflite_file, 'wb') as f:
f.write(quantized_and_pruned_tflite_model)
print('Saved quantized and pruned TFLite model to:', quantized_and_pruned_tflite_file)
print("Size of gzipped baseline Keras model: %.2f bytes" % (get_gzipped_model_size(keras_file)))
print("Size of gzipped pruned and quantized TFlite model: %.2f bytes" % (get_gzipped_model_size(quantized_and_pruned_tflite_file)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment