caffe-custom new layer

基本就是添加new_layer.cpp, new_layer.hpp, new_layer.cu三个文件, 以及修改caffe.prototxt(if the layer has parameter):

1. new_layer.hpp

NetLayer()构造函数

LayerSetup()函数

Reshape()函数

type()层名函数


Forward_cpu()

Forward_gpu()

Backward_cpu()

Backward_gpu()

note :这些函数都是虚函数 如果再次声明的话都需要实现, 所以如果没有实现就不要在这里写出来  会直接执行基类的相应的函数


2.  new_layer.cpp

LayerSetup()函数实现  // 初始化本层次的一些参数(一般从proto param) 

Reshape()函数实现  // 根据bottom blob和一些层次参数 计算得到top blob的shape


Forward_cpu() //implement   bottom.data->top.data      如果需要learnable参数则是本层次的blobs_

Backward_cpu() //implement  top.diff/loss -> bottom.diff    计算偏导数     


LOG(INFO)<< "something debug";  



3. new_layer.cu

nothing



INSTANTIATE_CLASS(NewLayer)    

REGISTER_LAYER_CLASS(New)   



测试方法流程,

train.prototxt    (force_backwaord: true)

solver.prototxt

solver = caffe.SGDsolver(solver)

solver.net.forward( )

solver.net.blobs['newlayer'].data/diff

solver.net.params[0/1].data


https://github.com/BVLC/caffe/blob/master/examples/01-learning-lenet.ipynb


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值