Contact Me:
王雪豪 xuehaowang@buaa.edu.cn
For a flexible operation on the Caffe Model, I public the brief code to modify paras.
The common layers, such as Conv layers, have two group paras, i.e. weights and bias.
Other layers, such as batchnorm layer, have three group paras, i.e. weights, bias and value for test phase.
If you use this code, call attention to the number of paras of the layer you modifed.
clc; clear all;
addpath(genpath('/usr/home/caffe-master/matlab/'));
caffe.reset_all();
use_gpu=1;
gpu_id=0;
if use_gpu
caffe.set_mode_gpu();
caffe.set_device(gpu_id);
else
caffe.set_mode_cpu();
end
% net = caffe.Net(model_config, model_file, 'test');
net = caffe.Net('./deploy_before.prototxt', './before.caffemodel', 'test');
net_after = caffe.Net('./deploy_after.prototxt', 'test');
net_after.params('conv_after', 1).set_data(net.params('conv_befor', 1).get_data()); % set weights
net_after.params('conv_after', 2).set_data(net.params('conv_befor', 2).get_data()); % set bias
net_after.save('net_modify.caffemodel');
caffe.reset_all();