Skip to content
longjon edited this page Jul 23, 2014 · 1 revision

Developing new layers

  1. Add a class declaration for your layer to the appropriate one of common_layers.hpp, data_layers.hpp, loss_layers.hpp, neuron_layers.hpp, or vision_layers.hpp. Include an inline implementation of type and the *Blobs() methods to specify blob number requirements. Omit the *_gpu declarations if you'll only be implementing CPU code.
  2. Implement your layer in layers/your_layer.cpp.
  • SetUp for initialization: reading parameters, allocating buffers, etc.
  • Forward_cpu for the function your layer computes
  • Backward_cpu for its gradient
  1. (Optional) Implement the GPU versions Forward_gpu and Backward_gpu in layers/your_layer.cu.
  2. Add your layer to proto/caffe.proto, updating the next available ID. Also declare parameters, if needed, in this file.
  3. Make your layer createable by adding it to layer_factory.cpp.
  4. Write tests in test/test_your_layer.cpp. Use test/test_gradient_check_util.hpp to check that your Forward and Backward implementations are in numerical agreement.
Clone this wiki locally