Using Python Layer__python in Caffe

Source: Internet
Author: User

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

1
With_python_layer:=1

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.