diff options
author | Przemysław Dolata <snowball91b@gmail.com> | 2018-08-17 11:54:36 +0200 |
---|---|---|
committer | Wook Song <wook16.song@samsung.com> | 2020-01-23 22:50:47 +0900 |
commit | fe062ef6983f8ebefd8f2d6c140fd5c548dca59c (patch) | |
tree | 8952d64c74a589f58e830604bad7c2bfc26d57e1 | |
parent | 34bcf358c299efae4f1d9415d525b28a45c29dda (diff) | |
parent | 33f74de2b4553d9643afca4ad3e4fa6bb169fc5d (diff) | |
download | caffe-fe062ef6983f8ebefd8f2d6c140fd5c548dca59c.tar.gz caffe-fe062ef6983f8ebefd8f2d6c140fd5c548dca59c.tar.bz2 caffe-fe062ef6983f8ebefd8f2d6c140fd5c548dca59c.zip |
Merge pull request #6282 from Noiredd/pooling-mode
PoolingLayer customizable output shape rounding mode
-rw-r--r-- | include/caffe/layers/pooling_layer.hpp | 1 | ||||
-rw-r--r-- | src/caffe/layers/pooling_layer.cpp | 21 | ||||
-rw-r--r-- | src/caffe/proto/caffe.proto | 6 |
3 files changed, 24 insertions, 4 deletions
diff --git a/include/caffe/layers/pooling_layer.hpp b/include/caffe/layers/pooling_layer.hpp index f4d6803b..38a43283 100644 --- a/include/caffe/layers/pooling_layer.hpp +++ b/include/caffe/layers/pooling_layer.hpp @@ -51,6 +51,7 @@ class PoolingLayer : public Layer<Dtype> { int height_, width_; int pooled_height_, pooled_width_; bool global_pooling_; + PoolingParameter_RoundMode round_mode_; Blob<Dtype> rand_idx_; Blob<int> max_idx_; }; diff --git a/src/caffe/layers/pooling_layer.cpp b/src/caffe/layers/pooling_layer.cpp index 90897db0..f2a08857 100644 --- a/src/caffe/layers/pooling_layer.cpp +++ b/src/caffe/layers/pooling_layer.cpp @@ -35,6 +35,7 @@ void PoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, || (!pool_param.has_stride_h() && !pool_param.has_stride_w())) << "Stride is stride OR stride_h and stride_w are required."; global_pooling_ = pool_param.global_pooling(); + round_mode_ = pool_param.round_mode(); if (global_pooling_) { kernel_h_ = bottom[0]->height(); kernel_w_ = bottom[0]->width(); @@ -87,10 +88,22 @@ void PoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, kernel_h_ = bottom[0]->height(); kernel_w_ = bottom[0]->width(); } - pooled_height_ = static_cast<int>(ceil(static_cast<float>( - height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; - pooled_width_ = static_cast<int>(ceil(static_cast<float>( - width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + switch (round_mode_) { + case PoolingParameter_RoundMode_CEIL: + pooled_height_ = static_cast<int>(ceil(static_cast<float>( + height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; + pooled_width_ = static_cast<int>(ceil(static_cast<float>( + width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + break; + case PoolingParameter_RoundMode_FLOOR: + pooled_height_ = static_cast<int>(floor(static_cast<float>( + height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; + pooled_width_ = static_cast<int>(floor(static_cast<float>( + width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + break; + default: + LOG(FATAL) << "Unknown rounding mode."; + } if (pad_h_ || pad_w_) { // If we have padding, ensure that the last pooling starts strictly // inside the image (instead of at the padding); otherwise clip the last. diff --git a/src/caffe/proto/caffe.proto b/src/caffe/proto/caffe.proto index b9bb3f4d..f784aa96 100644 --- a/src/caffe/proto/caffe.proto +++ b/src/caffe/proto/caffe.proto @@ -936,6 +936,12 @@ message PoolingParameter { // If global_pooling then it will pool over the size of the bottom by doing // kernel_h = bottom->height and kernel_w = bottom->width optional bool global_pooling = 12 [default = false]; + // How to calculate the output size - using ceil (default) or floor rounding. + enum RoundMode { + CEIL = 0; + FLOOR = 1; + } + optional RoundMode round_mode = 13 [default = CEIL]; } message PowerParameter { |