一、數據准備
網絡結構: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
三、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、點擊運行
點擊添加到路徑。
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內容為
可得matlab可視化得到的網絡模型是
從圖中可輸出layer有6層(6個矩形),blob有9個(9個橢圓形或多邊形);
其中,InnerProduct(內積層,也即全連接層),存有權重信息。該權重尺寸為784x10,可推出blob的data的size為100x784,blob中的ip的size為100x10;
net.layer_vec中只有ip層的params不為空
其中第一個blob的size為748x10,為權重;第二個blob的size為10x1,為偏置參數。
得到的權值圖片為:caffe/matlab/ip_weight.bmp
end