Skip to content

Instantly share code, notes, and snippets.

@AkiyonKS
Created August 9, 2022 05:13
Show Gist options
  • Save AkiyonKS/120389c87bb1c1480095798221090176 to your computer and use it in GitHub Desktop.
Save AkiyonKS/120389c87bb1c1480095798221090176 to your computer and use it in GitHub Desktop.
def get_gzipped_model_size(file):
# Returns size of gzipped model, in bytes.
import os
import zipfile
_, zipped_file = tempfile.mkstemp('.zip')
with zipfile.ZipFile(zipped_file, 'w', compression=zipfile.ZIP_DEFLATED) as f:
f.write(file)
return os.path.getsize(zipped_file)
print("Size of gzipped baseline Keras model: %.2f bytes" % (get_gzipped_model_size(keras_file)))
print("Size of gzipped pruned Keras model: %.2f bytes" % (get_gzipped_model_size(pruned_keras_file)))
print("Size of gzipped pruned TFlite model: %.2f bytes" % (get_gzipped_model_size(pruned_tflite_file)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment