首页 > 技术文章 > 如何向caffe中添加层

HugoLester 2017-07-19 16:07 原文

修改caffe\src\caffe\proto\caffe.proto

在最后添加centerloss层的参数信息

 

message CenterLossParameter {
optional uint32 num_output = 1; // The number of outputs for the layer
optional FillerParameter center_filler = 2; // The filler for the centers
// The first axis to be lumped into a single inner product computation;
// all preceding axes are retained in the output.
// May be negative to index from the end (e.g., -1 for the last axis).
optional int32 axis = 3 [default = 1];
}

 

添加层类型信息,注意不能与其他层的数字相同。

 

optional CenterLossParameter center_loss_param = 148;

将cpu和gpu两个模式下运行的文件添加到src\caffe\layers\

如何编写层,请查看官方文档或者谷歌

3.添加层的头文件

向\include\caffe\layers\中添加头文件

 然后编译的命令和正常的不一样

cp Makefile.config.examples Makefile.config

vim Makefile.config
make -j8
make pycaffe
make distribute

4.修改bashrc

在最后加入:

PYTHONPATH=$/home/lester/caffe-bak/distribute/python:$PYTHONPATH
export PATH=/home/lester/caffe-bak/build/tools:$PATH
LD_LIBRARY_PATH=$/home/lester/caffe-bak/build/lib:$LD_LIBRARY_PATH

source ~/.bashrc

sudo vim /etc/profile

在最后加入:

export PYTHONPATH=/home/lester/caffe-bak/python:$PYTHONPATH

source /etc/profile

 

推荐阅读