Skip to content

Instantly share code, notes, and snippets.

@bafu
Created March 16, 2016 10:12
Show Gist options
  • Save bafu/7f855a98f424bbf510c9 to your computer and use it in GitHub Desktop.
Save bafu/7f855a98f424bbf510c9 to your computer and use it in GitHub Desktop.
Display the size of hidden layers in vgg16.
#!/usr/bin/python
# Display the size of hidden layers in vgg16.
import functools
import operator
import h5py
f = h5py.File('vgg16_weights.h5', 'r')
weight_counter = 0
for group in f.values():
if len(group) == 0:
continue
print(group.name)
for value in group.values():
ws = functools.reduce(operator.mul, value.shape, 1)
print('\ttype: {0} ({1} weights, {2}MB)'.format(value.shape, ws, float(ws)*4/1024/1024))
weight_counter += ws
print('weight number: {0} ({1}MB)'.format(weight_counter, float(weight_counter)*4/1024/1024))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment