Add your own network layer in the Caffe

Source: Internet
Author: User

Write in front:

Caffe has many network layers, the latest version of the code has covered many types of network layer, however, sometimes for a variety of reasons, its given network layer can not meet our requirements, it is necessary to change it to meet their own needs, thanks to the author of Open source code and many code maintainers.

Since the network layer in Caffe is given the layer base class directly or indirectly, when we need to add a new type, we need to choose our own base class, so that we can better take advantage of some of the existing methods of the base class. Our new class can be based on the
1. directly inherit from layer
2. Inherit from DataLayer
3. Inherit from Neuronlayer
4. Inherit from Losslayer
5. Or if you want to improve a layer of code directly, you can directly inherit the class, and make the corresponding changes.

Specific steps:

The first step is to add the header file. h, you can create a new header file yourself, or append to an existing header file, such as INCLUDE/DATALAYER.HPP, to define some class variables inside.

The second step, add the implementation file, create the class implementation function, put in the src/xxx.cpp, if there is cuda implementation, you need to add the corresponding. cu file implementation, the main need to write Layersetup, reshape, forward, backup function.

The third step is to register the class and add the corresponding class to the src/caffe/layer_factory.cpp, adding

REGISTER_LAYER_CLASS(MYLAYER, MyLayer);

Fourth step, in the Src/caffe/proto/caffe.proto file, add the corresponding class and class parameters.
Add a row in enum Layertype {}

enumLayerType {MYLAYER = ID }//其中MYLAYER 是新添加的类名,ID是类编号,注意不能更之前的重复。

Add Class Parameters again

optional MylayerParameter mylayer_param = ID2;//其中MylayerParameter 是网络层参数,ID2 是ID

Finally define class parameters

message MylayerParameter {  uint321;   bool2 [defaulttrue]; }

The fifth step, write the test file, this is optional, but in order to merge into GitHub, need to test pass.

Add your own network layer in the Caffe

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.