-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Dynamic ksize and strides with MaxPool and AvgPool #9514
Conversation
Can one of the admins verify this patch? |
This is fine for API review, but we'd like the Python changes to be separated into a follow-on change after 3 weeks, where you also bump the GraphDef version in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/public/version.h . This is to accommodate our 3-week limited forward compatibility goal mentioned here: |
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.
In general a nice and clean change. Thanks! I've put some comments in your 3 commits. The major issue is to make sure that current tests in pooling_ops_test.py cover your new changes and pass.
std::vector<int32> ksize = ksize_; | ||
std::vector<int32> stride = stride_; | ||
|
||
if (context->num_inputs() != 1) { |
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.
Should it be if (context->num_inputs() == 3)
since we know exactly there will be 3 inputs for this case?
@@ -250,8 +254,35 @@ class MaxPoolingGradOp : public OpKernel { | |||
OP_REQUIRES_OK(context, context->allocate_temp(DataTypeToEnum<int64>::v(), | |||
tensor_out.shape(), | |||
&tensor_out_arg_max)); | |||
std::vector<int32> ksize = ksize_; | |||
std::vector<int32> stride = stride_; | |||
if (context->num_inputs() != 3) { |
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.
Same comment here, should we use if (context->num_inputs() == 5)
since we already know?
PoolParameters params{context, ksize_, stride_, | ||
std::vector<int32> ksize = ksize_; | ||
std::vector<int32> stride = stride_; | ||
if (context->num_inputs() != 3) { |
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.
Same comment on context->num_inputs()
as other places.
std::vector<int32> ksize = ksize_; | ||
std::vector<int32> stride = stride_; | ||
|
||
if (context->num_inputs() != 1) { |
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.
Same comment on context->num_inputs()
elsewhere.
const int depth_window = ksize_[3]; | ||
std::vector<int32> ksize = ksize_; | ||
std::vector<int32> stride = stride_; | ||
if (context->num_inputs() != 2) { |
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.
Same comment, should we use num_inputs() == 4
?
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.
Thanks @yzhwang. The PR has been updated with all related issue fixed.
@@ -1452,17 +1452,6 @@ def testOpEdgeCases(self): | |||
if test.is_gpu_available(): | |||
pool_funcs.append(nn_ops.max_pool_with_argmax) | |||
for pool_func in pool_funcs: | |||
# Illegal strides. | |||
with self.assertRaisesRegexp( |
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.
Is there any specific reason to exclude this test?
@@ -491,6 +491,19 @@ def _AvgPoolGrad(op, grad): | |||
data_format=op.get_attr("data_format")) | |||
|
|||
|
|||
@ops.RegisterGradient("AvgPoolV2") | |||
def _AvgPoolGradV2(op, grad): |
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.
We should add tests that actually take in ksizes and strides as input tensors during session running, but not like the current tests where ksizes and strides are still provided when building the graph? So that we can test whether the change works. For example, we could define ksizes and strides as variables and feed values only when we run the session.
This in general holds for all the operators you changed: MaxPool, MaxPoolGrad, MaxPoolGradGrad, AvgPool, AvgPoolGrad, AvgPoolGradGrad.
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.
Thanks @yzhwang The PR has been updated with tests using placeholder now. Please take a look.
Can one of the admins verify this patch? |
@yongtang any update on this? Could you please rebase to resolve conflicts? |
This fix tries to fix the issue raised in 4746 where ksize is static (attr) with max_pool. This fix changes ksize to input tensor so that it is dynamic now. This fix fixes 4746. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
79f5e94
to
1a090b4
Compare
@tensorflow-jenkins test this please |
@@ -103,17 +103,18 @@ def _VerifyOneType(self, pool_func, input_sizes, ksize, strides, padding, | |||
t = test_util.NHWCToNCHW(t) | |||
ksize = test_util.NHWCToNCHW(ksize) | |||
strides = test_util.NHWCToNCHW(strides) | |||
k = array_ops.placeholder(dtypes.int32, shape=[4]) |
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.
Could you test with both placeholders and and numpy arrays?
@yongtang There are a number of test failures due to the changes, please address those. |
I'll close this, as it appears inactive. Please create a new PR if you would like to pick this back up. |
@yongtang is this still being worked on? It appears to be exactly what I need. |
This fix tries to fix the issue raised in #4746 where ksize and strides is static (attr) with max_pool (and avg_pool).
This fix changes ksize and strides to input tensor with
MaxPoolV2
andAvgPoolV2
so that it is dynamic now. This fix also deprecatesMaxPool
andAvgPool
.This fix fixes #4746.