@@ -160,13 +160,87 @@ void Pooling3DLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype> *> &bottom,
160160 for (int i = 0 ; i < top_count; ++i) {
161161 top_data[i] = 0 ;
162162 }
163-
163+ // The main loop
164+ for (int n = 0 ; n < num_; ++n) {
165+ for (int c = 0 ; c < channels_; ++c) {
166+ for (int pd = 0 ; pd < pooled_depth_; ++pd) {
167+ for (int ph = 0 ; ph < pooled_height_; ++ph) {
168+ for (int pw = 0 ; pw < pooled_width_; ++pw) {
169+ int dstart = pd * stride_d_ - pad_d0_;
170+ int hstart = ph * stride_h_ - pad_h0_;
171+ int wstart = pw * stride_w_ - pad_w0_;
172+ int dend = min (dstart + kernel_d_, depth_ + pad_d1_);
173+ int hend = min (hstart + kernel_h_, height_ + pad_h1_);
174+ int wend = min (wstart + kernel_w_, width_ + pad_w1_);
175+ int pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart);
176+ dstart = max (dstart, 0 );
177+ hstart = max (hstart, 0 );
178+ wstart = max (wstart, 0 );
179+ dend = min (dend, depth_);
180+ hend = min (hend, height_);
181+ wend = min (wend, width_);
182+ for (int d = dstart; d < dend; ++d) {
183+ for (int h = hstart; h < hend; ++h) {
184+ for (int w = wstart; w < wend; ++w) {
185+ top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] +=
186+ bottom_data[(d * height_ + h) * width_ + w];
187+ }
188+ }
189+ }
190+ top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] /= pool_size;
191+ }
192+ }
193+ }
194+ // compute offset
195+ int bottom_offset = depth_ * height_ * width_;
196+ int top_offset = pooled_depth_ * pooled_height_ * pooled_width_;
197+ bottom_data += bottom_offset;
198+ top_data += top_offset;
199+ }
200+ }
164201 break ;
165202 case Pooling3DParameter_PoolMethod_AVE_EXC_PAD:
166203 for (int i = 0 ; i < top_count; ++i) {
167204 top_data[i] = 0 ;
168205 }
169-
206+ // The main loop
207+ for (int n = 0 ; n < num_; ++n) {
208+ for (int c = 0 ; c < channels_; ++c) {
209+ for (int pd = 0 ; pd < pooled_depth_; ++pd) {
210+ for (int ph = 0 ; ph < pooled_height_; ++ph) {
211+ for (int pw = 0 ; pw < pooled_width_; ++pw) {
212+ int dstart = pd * stride_d_ - pad_d0_;
213+ int hstart = ph * stride_h_ - pad_h0_;
214+ int wstart = pw * stride_w_ - pad_w0_;
215+ int dend = min (dstart + kernel_d_, depth_ + pad_d1_);
216+ int hend = min (hstart + kernel_h_, height_ + pad_h1_);
217+ int wend = min (wstart + kernel_w_, width_ + pad_w1_);
218+ dstart = max (dstart, 0 );
219+ hstart = max (hstart, 0 );
220+ wstart = max (wstart, 0 );
221+ dend = min (dend, depth_);
222+ hend = min (hend, height_);
223+ wend = min (wend, width_);
224+ int pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart);
225+ for (int d = dstart; d < dend; ++d) {
226+ for (int h = hstart; h < hend; ++h) {
227+ for (int w = wstart; w < wend; ++w) {
228+ top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] +=
229+ bottom_data[(d * height_ + h) * width_ + w];
230+ }
231+ }
232+ }
233+ top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] /= pool_size;
234+ }
235+ }
236+ }
237+ // compute offset
238+ int bottom_offset = depth_ * height_ * width_;
239+ int top_offset = pooled_depth_ * pooled_height_ * pooled_width_;
240+ bottom_data += bottom_offset;
241+ top_data += top_offset;
242+ }
243+ }
170244 break ;
171245 default :
172246 LOG (FATAL) << " Unknown pooling method." ;
0 commit comments