Skip to content

Instantly share code, notes, and snippets.

@jeffdonahue
Created May 10, 2016 01: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 jeffdonahue/e67bf4ed8b8f1c4dfadbb99009d593a1 to your computer and use it in GitHub Desktop.
Save jeffdonahue/e67bf4ed8b8f1c4dfadbb99009d593a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# usage: python count_caffemodel_params.py /path/to/my.caffemodel [/path/to/my/other.caffemodel, ...]
from caffe.proto import caffe_pb2
import sys
assert len(sys.argv) >= 2
for caffemodel_filename in sys.argv[1:]:
with open(caffemodel_filename, 'r') as caffemodel_file:
caffemodel = caffemodel_file.read()
net = caffe_pb2.NetParameter()
net.ParseFromString(caffemodel)
param_count = 0
for layer in net.layer:
for blob in layer.blobs:
param_count += len(blob.data)
print '%s: %d parameters' % (caffemodel_filename, param_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment