import caffe class My_Custom_Layer(caffe.Layer): def setup(self, bottom, top): pass def forward(self, bottom, top): pass def reshape(self, bottom, top): pass def backward(self, bottom, top): pass
So important things to remember:
The Setup method is called once during the lifetime of the execution, when Caffe is instantiating all layers. This is where you will read parameters, instantiate fixed-size buffers.
Use the reshape method for initialization/setup that depends on the bottom blob (layer input) size. It is called once when the network is instantiated.
The Forward method is called for each input batch and is where most of your logic will be.
The Backward method is called during the backward pass of the network. For example, in a convolution-like layer, this would be where you would calculate the gradients. This is optional (a layer can be forward-only).