首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Caffe LENET或Imagenet模型中的参数数量

Caffe LENET或Imagenet模型中的参数数量
EN

Stack Overflow用户
提问于 2015-05-23 02:31:15
回答 2查看 4.4K关注 0票数 10

如何计算模型中的参数数量,例如用于mnist的LENET,或用于imagent模型的ConvNet等。在caffe中是否有任何特定的函数来返回或保存模型中的参数数量。问候

EN

回答 2

Stack Overflow用户

发布于 2016-09-25 22:19:35

以下是计算Caffe模型中参数数量的python代码片段:

代码语言:javascript
复制
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

https://gist.github.com/kaushikpavani/a6a32bd87fdfe5529f0e908ed743f779

票数 4
EN

Stack Overflow用户

发布于 2015-07-14 14:46:59

我可以通过Matlab接口提供一种明确的方法(确保首先安装matcaffe )。基本上,您从每个网络层提取一组参数并对它们进行计数。在Matlab中:

代码语言:javascript
复制
% load the network
net_model = <path to your *deploy.prototxt file>
net_weights = <path to your *.caffemodel file>
phase = 'test';
test_net = caffe.Net(net_model, net_weights, phase);

% get the list of layers
layers_list = test_net.layer_names;
% for those layers which have parameters, count them
counter = 0;
for j = 1:length(layers_list),
    if ~isempty(test_net.layers(layers_list{j}).params)
    feat = test_net.layers(layers_list{j}).params(1).get_data();
    counter = counter + numel(feat)
    end
end

最后,'counter‘包含参数的数量。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30403590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档