Skip to content

Commit d2680ac

Browse files
committed
Add the pooling layer ceil_mode patch for DenseNet.
1 parent a4bfe4a commit d2680ac

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

include/caffe/layers/pooling_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class PoolingLayer : public Layer<Dtype> {
5454
Blob<Dtype> rand_idx_;
5555
Blob<int> max_idx_;
5656
int pad_type_; //CUSTOMIZATION
57+
bool ceil_mode_;
5758
};
5859

5960
} // namespace caffe

src/caffe/layers/pooling_layer.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void PoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
3535
|| (!pool_param.has_stride_h() && !pool_param.has_stride_w()))
3636
<< "Stride is stride OR stride_h and stride_w are required.";
3737
global_pooling_ = pool_param.global_pooling();
38+
ceil_mode_ = pool_param.ceil_mode();
3839
if (global_pooling_) {
3940
kernel_h_ = bottom[0]->height();
4041
kernel_w_ = bottom[0]->width();
@@ -102,10 +103,19 @@ void PoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
102103
//<--CUSTOMIZATION
103104
switch (pad_type_) {
104105
case 0:
105-
pooled_height_ = static_cast<int>(ceil(static_cast<float>(
106-
height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1;
107-
pooled_width_ = static_cast<int>(ceil(static_cast<float>(
108-
width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1;
106+
// Specify the structure by ceil or floor mode
107+
if (ceil_mode_) {
108+
pooled_height_ = static_cast<int>(ceil(static_cast<float>(
109+
height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1;
110+
pooled_width_ = static_cast<int>(ceil(static_cast<float>(
111+
width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1;
112+
}
113+
else{
114+
pooled_height_ = static_cast<int>(floor(static_cast<float>(
115+
height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1;
116+
pooled_width_ = static_cast<int>(floor(static_cast<float>(
117+
width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1;
118+
}
109119
break;
110120
case 1: //for "SAME"padding
111121
pooled_height_ = static_cast<int>(ceil(static_cast<float>(height_) / static_cast<float>(stride_h_)));

src/caffe/proto/caffe.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ message PoolingParameter {
13901390
// If global_pooling then it will pool over the size of the bottom by doing
13911391
// kernel_h = bottom->height and kernel_w = bottom->width
13921392
optional bool global_pooling = 12 [default = false];
1393+
optional bool ceil_mode = 14 [default = true]; // Specify floor/ceil mode
13931394
}
13941395

13951396
message PowerParameter {

0 commit comments

Comments
 (0)