nian-liu / PiCANet

37 stars 14 forks source link

need help for computing the number of parameters in each layer #2

Closed ArcherFMY closed 6 years ago

ArcherFMY commented 6 years ago

Hi,

Thanks for your great work!

I got problems when compiling the provided caffe on my computer, as follows:

.build_release/lib/libcaffe.so: undefined reference to `cblas_sgemv'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dgemm'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sscal'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dgemv'
.build_release/lib/libcaffe.so: undefined reference to `cblas_saxpy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_ddot'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dasum'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sgemm'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dscal'
.build_release/lib/libcaffe.so: undefined reference to `cblas_scopy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sasum'
.build_release/lib/libcaffe.so: undefined reference to `cblas_daxpy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dcopy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sdot'
collect2: error: ld returned 1 exit status
Makefile:616: recipe for target '.build_release/tools/convert_imageset.bin' failed
make: *** [.build_release/tools/convert_imageset.bin] Error 1
make: *** Waiting for unfinished jobs....
.build_release/lib/libcaffe.so: undefined reference to `cblas_sgemv'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dgemm'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sscal'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dgemv'
.build_release/lib/libcaffe.so: undefined reference to `cblas_saxpy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_ddot'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dasum'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sgemm'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dscal'
.build_release/lib/libcaffe.so: undefined reference to `cblas_scopy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sasum'
.build_release/lib/libcaffe.so: undefined reference to `cblas_daxpy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_dcopy'
.build_release/lib/libcaffe.so: undefined reference to `cblas_sdot'
collect2: error: ld returned 1 exit status
Makefile:616: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

After searching the solutions, I am still trapped with this error.

I want to compute the number of parameters in your model using the following codes:

matlab

clc;clear;
close all;

%% init
% Add caffe/matlab to my Matlab search PATH to use matcaffe
if exist('../+caffe','dir')
    addpath('..');
else
    error('Please run this from caffe/matlab/demo');
end

% Set caffe mode
use_gpu     = true;
if exist('use_gpu', 'var') && use_gpu
    caffe.set_mode_gpu();
    gpu_id = 0;
    caffe.set_device(gpu_id);
else
    caffe.set_mode_cpu();
end

net_model       = '/path/to/deploy.prototxt';
phase           = 'test';

% Initialize a network
net         = caffe.Net(net_model, phase);
fprintf('Init Done!');

num_layers = length(net.layer_names);
num_params = 0;
count = 0;
count_layers = [];
for iter_layer = 1 : num_layers
    fprintf('processing/total %d/%d\n', iter_layer, num_layers);
    layer_name = net.layer_names(iter_layer);
    layer_name = layer_name{1,1};
    layer_type = net.layers(layer_name).type;
    c = 1;
    while 1
        try
            count = count + prod(size(net.params(layer_name,c).get_data()));
            count_layers = [count_layers; prod(size(net.params(layer_name,c).get_data()))];
            c = c + 1;
        catch
            break;
        end
    end
end
caffe.reset_all()
fprintf('Total number of parameters: %d\n', count);

python

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 = "/path/to/deploy.prototxt"
print_net_parameters(deploy_file)

since I could not compile the caffe on my computer, would you mind computing the number of parameters for me?

Thanks a lot!!

ArcherFMY commented 6 years ago

problem solved,

https://github.com/BVLC/caffe/issues/2353