想要在现有的caffe版本添加ROIPoolingLayer 和SmoothL1LossLayer,首先到这里https://github.com/rbgirshick/caffe-fast-rcnn可以找到他们的定义。caffe添加layer的详细方法在这里可以看到https://github.com/BVLC/caffe/wiki/,然后我们就可以开始啦!!
1.ROIPoolingLayer 和SmoothL1LossLayer的声明与实现:
声明:caffe_root/include/caffe/fast_rcnn_layers.hpp
实现:caffe_root/src/caffe/layers/roi_pooling_layer.cpp
caffe_root/src/caffe/layers/roi_pooling_layer.cu
caffe_root/src/caffe/layers/smooth_L1_loss_layer.cpp
caffe_root/src/caffe/layers/smooth_L1_loss_layer.cu
2.ROIPoolingLayer 和SmoothL1LossLayer的测试:
caffe_root/src/caffe/test/test_roi_pooling_layer.cpp
caffe_root/src/caffe/test/test_smooth_L1_loss_layer.cpp
3.注册
caffe_root/src/caffe/proto/caffe.proto添加
optional ROIPoolingParameter roi_pooling_param = 8266711;
// Message that stores parameters used by ROIPoolingLayer
message ROIPoolingParameter {
// Pad, kernel size, and stride are all given as a single value for equal
// dimensions in height and width or as Y, X pairs.
optional uint32 pooled_h = 1 [default = 0]; // The pooled output height
optional uint32 pooled_w = 2 [default = 0]; // The pooled output width
// Multiplicative spatial scale factor to translate ROI coords from their
// input scale to the scale used when pooling
optional float spatial_scale = 3 [default = 1];
}
optional SmoothL1LossParameter smooth_l1_loss_param = 8266712;
message SmoothL1LossParameter {
// SmoothL1Loss(x) =
// 0.5 * (sigma * x) ** 2 -- if x < 1.0 / sigma / sigma
// |x| - 0.5 / sigma / sigma -- otherwise
optional float sigma = 1 [default = 1];
}
然后就大功告成了,重新编译caffe吧。