Skip to content

Instantly share code, notes, and snippets.

@lukmanr
Created October 17, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukmanr/5d2d7c93eb541c9416cbb2751f270e0b to your computer and use it in GitHub Desktop.
Save lukmanr/5d2d7c93eb541c9416cbb2751f270e0b to your computer and use it in GitHub Desktop.
TF Model Optimization 4
def get_size(model_dir, model_file='saved_model.pb'):
model_file_path = os.path.join(model_dir, model_file)
print(model_file_path, '')
pb_size = os.path.getsize(model_file_path)
variables_size = 0
if os.path.exists(
os.path.join(model_dir,'variables/variables.data-00000-of-00001')):
variables_size = os.path.getsize(os.path.join(
model_dir,'variables/variables.data-00000-of-00001'))
variables_size += os.path.getsize(os.path.join(
model_dir,'variables/variables.index'))
print('Model size: {} KB'.format(round(pb_size/(1024.0),3)))
print('Variables size: {} KB'.format(round( variables_size/(1024.0),3)))
print('Total Size: {} KB'.format(round((pb_size + variables_size)/(1024.0),3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment