Computer vision Caffe LENET或Imagenet模型中的参数数

Computer vision Caffe LENET或Imagenet模型中的参数数,computer-vision,neural-network,deep-learning,caffe,matcaffe,Computer Vision,Neural Network,Deep Learning,Caffe,Matcaffe,如何计算模型中的参数数量,例如mnist的LENET或imagent模型的ConvNet等。 caffe中是否有返回或保存模型中参数数量的特定函数。 关于我可以通过Matlab接口提供一种明确的方法来实现这一点(确保首先安装了matcaffe)。 基本上,您可以从每个网络层提取一组参数并对其进行计数。 在Matlab中: % load the network net_model = <path to your *deploy.prototxt file> net_weights =

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

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

% 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
%加载网络
网络模型=
净重=
阶段=‘测试’;
test_net=caffe.net(净模型、净权重、阶段);
%获取图层列表
层列表=测试层网络层名称;
%对于具有参数的图层,对其进行计数
计数器=0;
对于j=1:长度(层列表),
if~isempty(test_net.layers(layers_list{j}).params)
feat=test_net.layers(layers_list{j}).params(1.get_data();
计数器=计数器+努梅尔(专长)
结束
结束

最后,“counter”包含参数的数量

下面是一个python代码片段,用于计算Caffe模型中的参数数量:

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

将CNN加载到变量net后,查看net.params。它包含每个层的参数(权重和偏差)。您知道使用terminal for caffe的命令吗。但是我找到了法穆拉。i、 e.过滤器x通道x内核宽度x内核高度+偏差。这将在一个图层上为您提供参数。其他人也是如此。但是,我需要在caffe中使用终端的任何命令,例如,在matlab中,您可以说我们有numel(net.params)。caffe的github中有一个开放的功能。感谢您提出此请求。@khan似乎没有人接受此功能请求。如果其他人能在github上对该线程发表评论,引起caffe社区的注意,那将是一件好事。