Matconvnet 的一些记录
Matconvnet 的一些记录
Example code from ADNet: Action-Decision Networks for Visual Tracking with Deep Reinforcement Learning [Paper]
GitHub:https://github.com/hellbell/ADNet
1. 加载一个模型,然后去掉某些层,,如将 Conv + fc 改为 全卷机的(only Conv):
function [net, net_conv, net_fc] = split_dagNN(net) net.move('cpu'); net_fc = copy(net); net_conv = copy(net); % remove the fc layers, only the convolutional layers remained. layer_names = {}; for ii = 1 : 10 layer_names{ii} = net_fc.layers(ii).name; end net_fc.removeLayer(layer_names); net_fc.rebuild(); % remove the convolutional layers, and only the fc layers remained. layer_names = {}; for ii = 11 : numel(net.layers) layer_names{ii-10} = net_conv.layers(ii).name; end net_conv.removeLayer(layer_names); net_conv.rebuild(); net.move('gpu'); net_fc.rebuild();
2. 得到特定 layer 的索引和值(index 和 value):
tutorial from:http://www.vlfeat.org/matconvnet/quick/
% run the CNN net.eval({'data', im_}) ; % obtain the CNN otuput scores = net.vars(net.getVarIndex('prob')).value ; %% net.getVarIndex('prob')---> 是分类输出概率的那个 layer 的index XXX,然后 net.var(XXX).value 输出的是:对应 XXX 的特定概率值。 scores = squeeze(gather(scores)) ; %% gather 应该是将 GPU data 转为 CPU data 的方法
3.
Stay Hungry,Stay Foolish ...