我寫了一個簡單的腳本來計算給定體系結構的參數數量。這就是:GoogleNet有多少個參數?
#python caffe_param_calc.py deploy.prototxt
#or just call the script without any arguments, and it will search and show any deploy you have in the current directory
import sys
import os
import caffe
import numpy as np
from numpy import prod, sum
from pprint import pprint
def print_net_parameters (deploy_file):
print "Net: " + deploy_file
caffe.set_mode_cpu()
net = caffe.Net(deploy_file, caffe.TEST)
print "Layer-wise parameters: "
pprint([(k, v[0].data.shape) for k, v in net.params.items()])
num = sum([prod(v[0].data.shape) for k, v in net.params.items()])
print ("Total number of parameters: {0:,} ".format(num))
print (len(sys.argv))
if len(sys.argv) > 1 :
deploy_file = sys.argv[1]
else:
for file in os.listdir('.'):
if (file.endswith('.prototxt')):
deploy_file = file
print_net_parameters(deploy_file)
我用這對GoogleNet並獲得11,193,984
所使用的參數的數量,而在他們的論文,如果你在表1中添加了所有他們列出的參數,參數的總數成爲670萬!而且這表格似乎也不準確!我現在的問題是,我是否正確地做到了這一點?我在不同的體系結構上使用了相同的腳本,並獲得了正確的結果。
例如VGGNet(Link)的參數總數爲102,897,440。
Layer-wise parameters:
[('conv1', (96L, 3L, 7L, 7L)),
('conv2', (256L, 96L, 5L, 5L)),
('conv3', (512L, 256L, 3L, 3L)),
('conv4', (512L, 512L, 3L, 3L)),
('conv5', (512L, 512L, 3L, 3L)),
('fc6', (4096L, 18432L)),
('fc7', (4096L, 4096L)),
('fc8', (1000L, 4096L))]
Total number of parameters: 102,897,440
偏向條款呢?注意不要統計''BatchNorm''圖層的參數。 – Shai
@Shai:不考慮Batchnorm層和鱗片。我測試了蝙蝠蛾和沒有批量標準,並獲得相同數量的參數 – Breeze