Created
September 25, 2016 14:14
-
-
Save kaushikpavani/a6a32bd87fdfe5529f0e908ed743f779 to your computer and use it in GitHub Desktop.
Calculate number of parameters in a Caffe model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import caffe | |
caffe.set_mode_cpu() | |
import numpy as np | |
from numpy import prod, sum | |
from pprint import pprint | |
def print_net_parameters (deploy_file): | |
print "Net: " + deploy_file | |
net = caffe.Net(deploy_file, caffe.TEST) | |
print "Layer-wise parameters: " | |
pprint([(k, v[0].data.shape) for k, v in net.params.items()]) | |
print "Total number of parameters: " + str(sum([prod(v[0].data.shape) for k, v in net.params.items()])) | |
deploy_file = "/home/ubuntu/deploy.prototxt" | |
print_net_parameters(deploy_file) | |
# Sample output: | |
# Net: /home/ubuntu/deploy.prototxt | |
# Layer-wise parameters: | |
#[('conv1', (96, 3, 11, 11)), | |
# ('conv2', (256, 48, 5, 5)), | |
# ('conv3', (384, 256, 3, 3)), | |
# ('conv4', (384, 192, 3, 3)), | |
# ('conv5', (256, 192, 3, 3)), | |
# ('fc6', (4096, 9216)), | |
# ('fc7', (4096, 4096)), | |
# ('fc8', (819, 4096))] | |
# Total number of parameters: 60213280 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment