Skip to content

Instantly share code, notes, and snippets.

@vincentzhang
Forked from rafaspadilha/customLayerTutorial.md
Created August 18, 2017 01:48
Show Gist options
  • Select an option

  • Save vincentzhang/80bc49bc007532fef3cacadab9e26ced to your computer and use it in GitHub Desktop.

Select an option

Save vincentzhang/80bc49bc007532fef3cacadab9e26ced to your computer and use it in GitHub Desktop.
Caffe Python Layer

How to create a custom Caffe layer in Python?

This tutorial will guide through the steps to create a simple custom layer for Caffe using python.

###Why would I want to do that? Usually you would create a custom layer to implement a funcionality that isn't available in Caffe, tuning it for your requirements.

###What will I need? Python and Caffe instaled and a sample layer template (provided bellow) so you can customize it.

##Layer Template

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:

  • Your custom layer has to inherit from caffe.Layer (so don't forget to import caffe);
  • You must define the four following methods: setup, forward, reshape, backward;

###Setup method

###Reshape method

###Forward method

###Backward method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment