| 15 | |
| 16 | template <typename Dtype> |
| 17 | LayerParameter SPPLayer<Dtype>::GetPoolingParam(const int pyramid_level, |
| 18 | const int bottom_h, const int bottom_w, const SPPParameter spp_param) { |
| 19 | LayerParameter pooling_param; |
| 20 | int num_bins = pow(2, pyramid_level); |
| 21 | |
| 22 | // find padding and kernel size so that the pooling is |
| 23 | // performed across the entire image |
| 24 | int kernel_h = ceil(bottom_h / static_cast<double>(num_bins)); |
| 25 | // remainder_h is the min number of pixels that need to be padded before |
| 26 | // entire image height is pooled over with the chosen kernel dimension |
| 27 | int remainder_h = kernel_h * num_bins - bottom_h; |
| 28 | // pooling layer pads (2 * pad_h) pixels on the top and bottom of the |
| 29 | // image. |
| 30 | int pad_h = (remainder_h + 1) / 2; |
| 31 | |
| 32 | // similar logic for width |
| 33 | int kernel_w = ceil(bottom_w / static_cast<double>(num_bins)); |
| 34 | int remainder_w = kernel_w * num_bins - bottom_w; |
| 35 | int pad_w = (remainder_w + 1) / 2; |
| 36 | |
| 37 | pooling_param.mutable_pooling_param()->set_pad_h(pad_h); |
| 38 | pooling_param.mutable_pooling_param()->set_pad_w(pad_w); |
| 39 | pooling_param.mutable_pooling_param()->set_kernel_h(kernel_h); |
| 40 | pooling_param.mutable_pooling_param()->set_kernel_w(kernel_w); |
| 41 | pooling_param.mutable_pooling_param()->set_stride_h(kernel_h); |
| 42 | pooling_param.mutable_pooling_param()->set_stride_w(kernel_w); |
| 43 | |
| 44 | switch (spp_param.pool()) { |
| 45 | case SPPParameter_PoolMethod_MAX: |
| 46 | pooling_param.mutable_pooling_param()->set_pool( |
| 47 | PoolingParameter_PoolMethod_MAX); |
| 48 | break; |
| 49 | case SPPParameter_PoolMethod_AVE: |
| 50 | pooling_param.mutable_pooling_param()->set_pool( |
| 51 | PoolingParameter_PoolMethod_AVE); |
| 52 | break; |
| 53 | case SPPParameter_PoolMethod_STOCHASTIC: |
| 54 | pooling_param.mutable_pooling_param()->set_pool( |
| 55 | PoolingParameter_PoolMethod_STOCHASTIC); |
| 56 | break; |
| 57 | default: |
| 58 | LOG(FATAL) << "Unknown pooling method."; |
| 59 | } |
| 60 | |
| 61 | return pooling_param; |
| 62 | } |
| 63 | |
| 64 | template <typename Dtype> |
| 65 | void SPPLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, |
nothing calls this directly
no outgoing calls
no test coverage detected