Because of Python's flexibility, it is more convenient to use the Python layer when adding a layer of our own definition in Caffe, and the speed of development will be faster than C + +. Now I'll just talk about it here. How to add a custom Python layer in Caffe (lenet structure when using the original network structure):
First add your own defined layer function. py file in the Caffe->python folder, for example I named mypythonlayer.py here, the function of this layer is to add a number to the input data, as follows:
Then add a new layer in/home/zf/caffe/examples/mnist/lenet_train_test.prototxt (adding the Python layer is a little bit different from adding the C + + layer before):
After you train with train_lenet.sh, you may get an error saying that the function requires the PROTOBUF version to be 3.3.0, But your machine is installed on the 2.6.1, so you may need to upgrade this error, you can refer to this link for protobuf3.3.0 installation
(http://blog.csdn.net/codertc/article/details/52022646)
After the training with train_lenet.sh is still the error, I still do not say how to solve, but at this time I can write. py file for training, as follows:
And then we can do the training.
Caffe Adding a python layer of your own writing