Turn from: http://blog.csdn.net/liuheng0111/article/details/53090473
http://blog.csdn.net/thesby/article/details/51264439
Caffe uses the Boost.python module in boost to support the use of Python definition layer: adding new layer with C + + is cumbersome, time-consuming, and easily error-prone between development speed and execution speed trade-off Compile support for Python layer Caffe
If this is the first compilation, modify the Makefile.cinfig,uncomment in the Caffe root directory
If you have already compiled
1
2
|
Make clean
with_python_layer=1 make&& make Pycaffe
|
using the Python Layer
Add a python-defined loss layer to the network's Prototxt file as follows:
1
2
3
4
5
6 7 8 9 (14)
|
layer{
type: ' Python '
name: ' Loss ' top
: ' Loss '
bottom: ' IPX '
bottom: ' ipy '
python_ param{
#module的名字, usually the file name of the. py file that defines the layer, required under $pythonpath
module: ' Pyloss '
#layer的名字---class name in module
layer: ' Euclideanlosslayer '
}
Loss_weight:1
}
|
define Python Layer
According to the above requirements, we are creating pyloss.py in $pythonpat and defining Euclideanlosslayer in it.
1
2
3
4
5
6 7 8 9 (15)
27 (or more)
|
Import Caffe
import NumPy as NP
|