@@ -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_)));
0 commit comments