码迷,mamicode.com
首页 > 其他好文 > 详细

如何在caffe中添加新类型的layer

时间:2015-06-16 18:32:39      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

如何在caffe中添加新类型的layer

参考:https://github.com/BVLC/caffe/issues/684

 

  1. Add a class declaration for your layer to the appropriate one of common_layers.hpp,data_layers.hpp, loss_layers.hpp, neuron_layers.hpp, or vision_layers.hpp. Include an inline implementation of type and the *Blobs() methods to specify blob number requirements. Omit the*_gpu declarations if you‘ll only be implementing CPU code.

  2. Implement your layer in layers/your_layer.cpp.

    • SetUp for initialization: reading parameters, allocating buffers, etc.

    • Forward_cpu for the function your layer computes

    • Backward_cpu for its gradient

     

  3. (Optional) Implement the GPU versions Forward_gpu and Backward_gpu in layers/your_layer.cu.

  4. Add your layer to proto/caffe.proto, updating the next available ID. Also declare parameters, if needed, in this file.

  5. Make your layer createable by adding it to layer_factory.cpp.

  6. Write tests in test/test_your_layer.cpp. Use test/test_gradient_check_util.hpp to check that your Forward and Backward implementations are in numerical agreement.

以上是github上某大神的解答,步骤很清晰,具体说一下,比如现在要添加一个vision layer,名字叫Aaa_Layer:

1、属于哪个类型的layer,就打开哪个hpp文件,这里就打开vision_layers.hpp,然后自己添加该layer的定义,或者直接复制Convolution_Layer的相关代码来修改类名和构造函数名都改为Aaa_Layer,如果不用GPU,将*_gpu的声明都去掉。

2、实现自己的layer,编写Aaa_Layer.cpp,加入到src/caffe/layers,主要实现Setup、Forward_cpu、Backward_cpu。

3、如果需要GPU实现,那么在Aaa_Layer.cu中实现Forward_gpu和Backward_gpu。

4、修改src/caffe/proto/caffe.proto,好到LayerType,添加Aaa,并更新ID,如果Layer有参数,添加AaaParameter类。

5、在src/caffe/layer_factory.cpp中添加响应代码。

6、在src/caffe/test中写一个test_Aaa_layer.cpp,用include/caffe/test/test_gradient_check_util.hpp来检查前向后向传播是否正确。

如何在caffe中添加新类型的layer

标签:

原文地址:http://www.cnblogs.com/yymn/p/4581095.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!