Skip to content

Commit e73a136

Browse files
committed
add round_mode into pooling param
origin is BVLC/caffe@24b0905 and we have some fix
1 parent 7e78f94 commit e73a136

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

include/caffe/layers/pooling_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PoolingLayer : public Layer<Dtype> {
5555
Blob<int> max_idx_;
5656
int pad_type_; //CUSTOMIZATION
5757
bool ceil_mode_;
58+
PoolingParameter_RoundMode round_mode_;
5859
int pad_l_; //CUSTOMIZATION
5960
int pad_r_; //CUSTOMIZATION
6061
int pad_t_; //CUSTOMIZATION

src/caffe/layers/pooling_layer.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,25 @@ 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();
38+
39+
if(pool_param.has_round_mode())
40+
{
41+
round_mode_ = pool_param.round_mode();
42+
switch (round_mode_) {
43+
case PoolingParameter_RoundMode_CEIL:
44+
ceil_mode_ = true;
45+
break;
46+
case PoolingParameter_RoundMode_FLOOR:
47+
ceil_mode_ = false;
48+
break;
49+
default:
50+
LOG(FATAL) << "Unknown rounding mode.";
51+
}
52+
}
53+
else{
54+
ceil_mode_ = pool_param.ceil_mode();
55+
}
56+
3957
if (global_pooling_) {
4058
kernel_h_ = bottom[0]->height();
4159
kernel_w_ = bottom[0]->width();

src/caffe/proto/caffe.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,12 @@ message PoolingParameter {
22122212
optional bool global_pooling = 12 [default = false];
22132213

22142214
optional bool ceil_mode = 14 [default = true]; // Specify floor/ceil mode rounding
2215+
// How to calculate the output size - using ceil (default) or floor rounding.
2216+
enum RoundMode {
2217+
CEIL = 0;
2218+
FLOOR = 1;
2219+
}
2220+
optional RoundMode round_mode = 15 [default = CEIL]; // functionality similar to ceil_mode; higher priority than ceil_mode
22152221
}
22162222

22172223
message Pooling3DParameter {

0 commit comments

Comments
 (0)