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
Add an optional switch to control edge behavior of average pooling #6303
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing this PR is missing is a test case for this functionality. As it is, it passes the tests because the default value of the flag is false
, so it's disabled and never tested.
Also, I left a couple minor comments in the review.
src/caffe/layers/pooling_layer.cpp
Outdated
@@ -127,6 +127,7 @@ void PoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, | |||
template <typename Dtype> | |||
void PoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, | |||
const vector<Blob<Dtype>*>& top) { | |||
PoolingParameter pool_param = this->layer_param_.pooling_param(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about, instead of reading the param every time, just add a class member variable to hold the value of the flag, and just set it once during LayerSetUp
?
src/caffe/layers/pooling_layer.cpp
Outdated
@@ -203,6 +204,9 @@ void PoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, | |||
wstart = max(wstart, 0); | |||
hend = min(hend, height_); | |||
wend = min(wend, width_); | |||
if (pool_param.dynamic_ave_pool_size() == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pool_param.dynamic_ave_pool_size())
will suffice. And if you decide to follow my advice from the comment above, it will get even simpler (if (member_var_)
).
src/caffe/layers/pooling_layer.cu
Outdated
hstart = max(hstart, 0); | ||
wstart = max(wstart, 0); | ||
hend = min(hend, height); | ||
wend = min(wend, width); | ||
if (dynamic_ave_pool_size == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like above: if (dynamic_ave_pool_size)
would be cleaner.
src/caffe/proto/caffe.proto
Outdated
// If dynamic_ave_pool_size is set to true, every iteration of AVE pooling will only | ||
// concerns valid elements: (sum of elements within kernel)/(valid elements num) | ||
// Otherwise, invalid padded elements will always be counted in the denominator | ||
optional bool dynamic_ave_pool_size = 13 [default = false]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My last comment and the most opinion-based: is this the best name for this flag? How about valid_ave_pooling
?
Also, while it's good that you've explained what this does, I think that the comment should make it more clear that valid pooling ignores the padding elements in the calculation.
Hi Noiredd, Thanks for help reviewing my fix. Now the code has been updated accordingly. Thanks, |
Seems something happened to Travis CI server, perhaps I need to try again later. |
Thanks for the fixes. One other thing: now that you use a member variable, we don't need to declare As I said, this passes tests because it is actually never tested - every time any test case instantiates a Pooling Layer, it does so with its default setting, which is without Those random Travis errors are obviously not related to the code, so let's not worry about them for now. If need be, I will restart the tests. |
The param declaration within Forward/Backward are removed now, and new ver. passed the travis. Yes, I suggest this needs specific tests, and I'm looking into the existed tests and learning to create one. Besides, I think this feature shall be both tested under the CPU and GPU backend. Thanks, |
I created an explicit test named "TestForwardAveValid", it will turn on the member variable valid_ave_pooling and compare the outputs. I noticed the comments in the cuDNN version tests, says cuDNN doesn't support padding. So I'm not quite sure about the test method in cuDNN version. If you would help take a review, it'll be much appreciated. Thanks, |
Must be some old information, I'm quite sure we can use padded pooling with cuDNN. Another thing is that the blob that you're using is quite trivial - filled with a constant value. Are you sure this will be a solid test? |
Sorry, I was busy working on other projects afterwards. The test blob that used in this test is imitating the existed average pool test, which is "TestForwardAve". I'm not 100% sure about the meaning of gradient test that in test_pooling_layer.cpp, like "TestGradientAve" corresponds to "TestForwardAve". I think my previous code modification shall be safe enough, however add a gradient test would also be a good idea. Would you help check the actual mechanism and sufficiency of "TestGradientAve". Thanks, |
Because the commits on old thread #6296 got messed up, I try to create this new thread based on a clean branch. Hi @Noiredd, would you please help close that thread, it will be very helpful.
I just tested the Forward_cpu() version, it seems good. I will test the GPU forward version later on, but need some help on the Backward_cpu().
Thanks,
Xiaolun Cao