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();

本文提供了一段用于灵活操作Caffe模型的代码,重点介绍了如何修改模型中常见层(如卷积层)的权重和偏置参数,以及其他层(如批归一化层)的额外参数。代码示例展示了如何将一个模型的参数复制到另一个模型中。
1042

被折叠的 条评论
为什么被折叠?



