Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in pooling_layer.cpp? #6881

Open
freeniliang opened this issue Dec 24, 2019 · 2 comments
Open

A bug in pooling_layer.cpp? #6881

freeniliang opened this issue Dec 24, 2019 · 2 comments

Comments

@freeniliang
Copy link

freeniliang commented Dec 24, 2019

@csukuangfj @Noiredd

Issue summary

A bug in pooling_layer.cpp?

original code:

if (pad_h_ || pad_w_) {
// If we have padding, ensure that the last pooling starts strictly
// inside the image (instead of at the padding); otherwise clip the last.`
if ((pooled_height_ - 1) * stride_h_ >= height_ + pad_h_) {
--pooled_height_;
}
if ((pooled_width_ - 1) * stride_w_ >= width_ + pad_w_) {
--pooled_width_;
}
CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);
CHECK_LT((pooled_width_ - 1) * stride_w_, width_ + pad_w_);
}
I think that “if (pad_h_ || pad_w_) ” should be removed!

For example:
Input feature map = hiwi= 66,kernel=1,stride=2,pad=0,round_mode=CEIL;
ho=ceil_div((6+2*0-1) ,2)+1=4
(ho-1)*stride=(4-1)*2=6=hi+pad=6+0
In this case, the 4th output point is out side of the input map, ho/wo must be decreased by 1!

So, “if (pad_h_ || pad_w_) ” should be removed!

@freeniliang freeniliang changed the title bug in pooling_layer.cpp bug in pooling_layer.cpp? Dec 24, 2019
@freeniliang freeniliang changed the title bug in pooling_layer.cpp? A bug in pooling_layer.cpp? Dec 24, 2019
@freeniliang freeniliang reopened this Dec 25, 2019
@csukuangfj
Copy link
Contributor

if (pad_h_ || pad_w_) {
// If we have padding, ensure that the last pooling starts strictly
// inside the image (instead of at the padding); otherwise clip the last.
if ((pooled_height_ - 1) * stride_h_ >= height_ + pad_h_) {
--pooled_height_;
}
if ((pooled_width_ - 1) * stride_w_ >= width_ + pad_w_) {
--pooled_width_;
}
CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);
CHECK_LT((pooled_width_ - 1) * stride_w_, width_ + pad_w_);
}

I think that “if (pad_h_ || pad_w_) ” should be removed!

You'll fail at line 116

CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);

In this case, the 4th output point is out side of the input map, ho/wo must be decreased by 1!

Pleas read the code further:

int hstart = ph * stride_h_ - pad_h_;
int wstart = pw * stride_w_ - pad_w_;
int hend = min(hstart + kernel_h_, height_);
int wend = min(wstart + kernel_w_, width_);
hstart = max(hstart, 0);
wstart = max(wstart, 0);
const int pool_index = ph * pooled_width_ + pw;
for (int h = hstart; h < hend; ++h) {

At line 175, h < hend will be false and the for loop is not executed.

@freeniliang
Copy link
Author

if (pad_h_ || pad_w_) {
// If we have padding, ensure that the last pooling starts strictly
// inside the image (instead of at the padding); otherwise clip the last.
if ((pooled_height_ - 1) * stride_h_ >= height_ + pad_h_) {
--pooled_height_;
}
if ((pooled_width_ - 1) * stride_w_ >= width_ + pad_w_) {
--pooled_width_;
}
CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);
CHECK_LT((pooled_width_ - 1) * stride_w_, width_ + pad_w_);
}

I think that “if (pad_h_ || pad_w_) ” should be removed!

You'll fail at line 116

CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);

In this case, the 4th output point is out side of the input map, ho/wo must be decreased by 1!

Pleas read the code further:

int hstart = ph * stride_h_ - pad_h_;
int wstart = pw * stride_w_ - pad_w_;
int hend = min(hstart + kernel_h_, height_);
int wend = min(wstart + kernel_w_, width_);
hstart = max(hstart, 0);
wstart = max(wstart, 0);
const int pool_index = ph * pooled_width_ + pw;
for (int h = hstart; h < hend; ++h) {

At line 175, h < hend will be false and the for loop is not executed.



“if (pad_h_ || pad_w_) ” should be removed!You'll fail at line 116
-----I think that line 116 will not fail, because pooled_height_/pooled_height_ is already decreased by 1, so, (pooled_height_ - 1) * stride_h_ must be less than height_ + pad_h_ at line 116;

At line 175, h < hend will be false and the for loop is not executed.
----- Yes, this loop will not be executed, but the number of output has been identified in the following below:

if (pad_h_ || pad_w_) {
// If we have padding, ensure that the last pooling starts strictly
// inside the image (instead of at the padding); otherwise clip the last.
if ((pooled_height_ - 1) * stride_h_ >= height_ + pad_h_) {
--pooled_height_;
}
if ((pooled_width_ - 1) * stride_w_ >= width_ + pad_w_) {
--pooled_width_;
}
CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);
CHECK_LT((pooled_width_ - 1) * stride_w_, width_ + pad_w_);
}

In this case, you will find that the data at the boundary(the most right/bottom) are invalid(AVE:0.0; MAX:-FLT_MAX).
In order to drop the invalid data, a slice layer must be added behind the pool layer, but if “if (pad_h_ || pad_w_) ” is removed, the output of pool layer can be used by next layer without inserting slice layer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants