This tutorial will guide through the steps to create a simple custom layer for Caffe using python. By the end of it, there are some examples of custom layers. Usually you would create a custom layer to implement a functionality that isn't available in Caffe, tuning it for your requirements.
Creating a python custom layer adds some overhead to your network and probably isn't as efficient as a C++ custom layer. However, this way, you won't have to compile the whole caffe with your new layer.
Parameter | Details |
---|---|
top | An array with the top blobs of your layer. Access data passed to it by using top[i].data, where i is the index of a specific blob |
bottom | An array with the bottom blobs of your layer. Access data passed to it by using bottom[i].data, where i is the index of a specific blob |
Caffe needs to be compiled with WITH_PYTHON_LAYER
option:
WITH_PYTHON_LAYER=1 make && make pycaffe
You have two options (at least that I know of). Either you can save the custom layer file in the same folder as you are going to run the caffe command (probably where your prototxt files would be). Another way, also my favorite one, is to save all your custom layers in a folder and adding this folder to your PYTHONPATH.