smbx-ztbz

一、数据准备

网络结构:lenet_lr.prototxt

训练好的模型:lenet_lr_iter_10000.caffemodel

下载地址:链接:https://pan.baidu.com/s/1uBDTKapT1yFHX4TEMaxQvQ 密码:2mla

 

二、利用pycaffe可视化,只需根据prototxt文件即可得到

~/caffe/caffe/examples/mnist$ python /home/tingpan/caffe/caffe/python/draw_net.py lenet_lr.prototxt lenet_lr.png

lenet_lr

 

三、matlab权值可视化

1、切换至caffe目录下,在matlab目录中新建mnist_lr_weights_vis.m

clear;
clc;
close all;
addpath(\'matlab\')
caffe.set_mode_cpu();
caffe.version()
net = caffe.Net(\'examples/mnist/lenet_lr.prototxt\' , ...
\'examples/mnist/lenet_lr_iter_10000.caffemodel\', \'test\');
net.layer_names
net.blob_names
ip_layer = net.layer_vec(3);
weight_blob = ip_layer.params(1);
w = weight_blob.get_data();
size(w) %784x10
bias_blob = ip_layer.params(2);
b = bias_blob.get_data();
size(b) %10x1
 
w = w - min(min(w));
w = w/(max(max(w)))*255;
w = uint8(w);
figure; imshow(w);
imwrite(w, \'./matlab/ip_weight.bmp\');
sprintf(\'finish\')

2、点击运行

Image

点击添加到路径。

3、输出:

ans =

1.0.0


ans =

  6×1 cell 数组

    \'mnist\'
    \'label_mnist_1_split\'
    \'ip\'
    \'ip_ip_0_split\'
    \'accuracy\'
    \'loss\'


ans =

  9×1 cell 数组

    \'data\'
    \'label\'
    \'label_mnist_1_split_0\'
    \'label_mnist_1_split_1\'
    \'ip\'
    \'ip_ip_0_split_0\'
    \'ip_ip_0_split_1\'
    \'accuracy\'
    \'loss\'


ans =

   784    10


ans =

    10     1


ans =

finish

4、分析

net内容为

Image

可得matlab可视化得到的网络模型是

lenet_lr_matlab

从图中可输出layer有6层(6个矩形),blob有9个(9个椭圆形或多边形);

其中,InnerProduct(内积层,也即全连接层),存有权重信息。该权重尺寸为784x10,可推出blob的data的size为100x784,blob中的ip的size为100x10;

net.layer_vec中只有ip层的params不为空

Image

其中第一个blob的size为748x10,为权重;第二个blob的size为10x1,为偏置参数。

得到的权值图片为:caffe/matlab/ip_weight.bmp

ip_weight

end

分类:

技术点:

相关文章: