caffe下添加新的loss层

caffe的使用当中,最神秘的就是caffe的源码,而我们要做一些创新点的话,基本上都是要修改caffe的源码。
小鱼和大家分享怎么在caffe下添加新的层。
比如要添加一个新的loss函数:euclidean_loss_norm_layer

1、需要编写相应的euclidean_loss_norm_layer.cpp和相应的euclidean_loss_norm_layer.cu文件,.cpp文件是实现cpu下函数的前传与反传,.cu文件是实现gpu下函数的前传与反传;
2、将euclidean_loss_norm_layer.cpp和
euclidean_loss_norm_layer.cu文件放入caffe/src/caffe/layers文件夹下;
3、编写对应的euclidean_loss_norm_layer.hpp文件,放入caffe/include/caffe/layers文件夹下;
4、在caffe/src/caffe/proto/caffe.proto文件下添加对应的optional及meaasge,如下:

optional EuclideanLossNormParameter euclidean_loss_norm_param = 149; 
message EuclideanLossNormParameter {
  // The axis along which to concatenate -- may be negative to index from the
  // end (e.g., -1 for the last axis).  Other axes must have the
  // same dimension for all the bottom blobs.
  // By default, ConcatLayer concatenates blobs along the "channels" axis (1).
 // optional int32 axis = 2 [default = 1];

  // DEPRECATED: alias for "axis" -- does not support negative indexing.
  //optional uint32 concat_dim = 1 [default = 1];
}

5、重新在caffe下make clean及make all,编译通过即可。

如果喜欢请点个赞再走哦,有什么问题请留言区讨论,一起学习。

猜你喜欢

转载自blog.csdn.net/zllljf/article/details/80970557
今日推荐