Skip to content

Commit

Permalink
implement the avg and tf avg style pooling 3d
Browse files Browse the repository at this point in the history
  • Loading branch information
vera121 committed Feb 24, 2020
1 parent 5ddc4da commit 67f074b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
3 changes: 2 additions & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
A Short Summary of New Features in Synopsys Caffe
=================================================

Synopsys Caffe Version: 2019.12
Synopsys Caffe Version: 2020.03
New added features are compared with the original BVLC Caffe 1.0.0

evconvert (TensorFlow/ONNX/... to Caffe Converter) related
Expand Down Expand Up @@ -39,6 +39,7 @@ one_hot_layer
pad_layer
peephole_lstm_layer
piece_layer
pooling3d_layer
pow_layer
pyramid_roi_align_layer
range_layer
Expand Down
78 changes: 76 additions & 2 deletions src/caffe/layers/pooling3d_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,87 @@ void Pooling3DLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype> *> &bottom,
for (int i = 0; i < top_count; ++i) {
top_data[i] = 0;
}

// The main loop
for (int n = 0; n < num_; ++n) {
for (int c = 0; c < channels_; ++c) {
for (int pd = 0; pd < pooled_depth_; ++pd) {
for (int ph = 0; ph < pooled_height_; ++ph) {
for (int pw = 0; pw < pooled_width_; ++pw) {
int dstart = pd * stride_d_ - pad_d0_;
int hstart = ph * stride_h_ - pad_h0_;
int wstart = pw * stride_w_ - pad_w0_;
int dend = min(dstart + kernel_d_, depth_ + pad_d1_);
int hend = min(hstart + kernel_h_, height_ + pad_h1_);
int wend = min(wstart + kernel_w_, width_ + pad_w1_);
int pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart);
dstart = max(dstart, 0);
hstart = max(hstart, 0);
wstart = max(wstart, 0);
dend = min(dend, depth_);
hend = min(hend, height_);
wend = min(wend, width_);
for (int d = dstart; d < dend; ++d) {
for (int h = hstart; h < hend; ++h) {
for (int w = wstart; w < wend; ++w) {
top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] +=
bottom_data[(d * height_ + h) * width_ + w];
}
}
}
top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] /= pool_size;
}
}
}
// compute offset
int bottom_offset = depth_ * height_ * width_;
int top_offset = pooled_depth_ * pooled_height_ * pooled_width_;
bottom_data += bottom_offset;
top_data += top_offset;
}
}
break;
case Pooling3DParameter_PoolMethod_AVE_EXC_PAD:
for (int i = 0; i < top_count; ++i) {
top_data[i] = 0;
}

// The main loop
for (int n = 0; n < num_; ++n) {
for (int c = 0; c < channels_; ++c) {
for (int pd = 0; pd < pooled_depth_; ++pd) {
for (int ph = 0; ph < pooled_height_; ++ph) {
for (int pw = 0; pw < pooled_width_; ++pw) {
int dstart = pd * stride_d_ - pad_d0_;
int hstart = ph * stride_h_ - pad_h0_;
int wstart = pw * stride_w_ - pad_w0_;
int dend = min(dstart + kernel_d_, depth_ + pad_d1_);
int hend = min(hstart + kernel_h_, height_ + pad_h1_);
int wend = min(wstart + kernel_w_, width_ + pad_w1_);
dstart = max(dstart, 0);
hstart = max(hstart, 0);
wstart = max(wstart, 0);
dend = min(dend, depth_);
hend = min(hend, height_);
wend = min(wend, width_);
int pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart);
for (int d = dstart; d < dend; ++d) {
for (int h = hstart; h < hend; ++h) {
for (int w = wstart; w < wend; ++w) {
top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] +=
bottom_data[(d * height_ + h) * width_ + w];
}
}
}
top_data[(pd * pooled_height_ + ph) * pooled_width_ + pw] /= pool_size;
}
}
}
// compute offset
int bottom_offset = depth_ * height_ * width_;
int top_offset = pooled_depth_ * pooled_height_ * pooled_width_;
bottom_data += bottom_offset;
top_data += top_offset;
}
}
break;
default:
LOG(FATAL) << "Unknown pooling method.";
Expand Down

0 comments on commit 67f074b

Please sign in to comment.