How to add a new layer on caffe network?
The official but outdated document
can be found:https://github.com/BVLC/caffe/wiki/Developmentand
useful links:https://yunmingzhang.wordpress.com/2015/01/19/how-to-create-your-own-layer-in-deep-learning-framework-caffe/
In this work, we try to add a verysimple layer: a linear function f(x)=0.5(x)+0.1 as activation layer (justsimilar to sigma and tahn) to illustrate the way to add new layer to Caffe.
Step 1: you should create a newclass in caffe_root/inclide/caffexx.hppfile.
Similar to sigma, it should be addedto neuron_layers.hpp
If you want to use GPU version,uncomment gpu functions and implement it in linear_layer.cu
Step2: Assign new ID to your layer
Incaffe_root/src/caffe/proto/caffe.proto, we define our layer as LINEAR andassign ID=38 (can be other number), meanwhile, we assign layer parameter ID
Setp 3: Implement linear layer incaffe_root/src/caffe/layers.
Create a new .cpp file as“linear_layer.cpp”,there are fourmethods might be implemented
·LayerSetUp(optional): for
one-time initialization: reading parameters, fixed-size allocations, etc.
·Reshape:for computing the sizes of top blobs,allocating buffers, and any other work that depends on the shapes of bottomblobs
·Forward_cpu:for the
function your layer computes
·Backward_cpu:for its
gradient (Optional -- a layer can be forward-only)
Here, we implement CPU version ofForward and Backward
Step 4: Instantiate and register
your layer in your cpp file with the macro provided inlayer_factory.hpp.
Step 5: add newlayer to train_test_prototxt,compileand run!
��*���G�