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

Dynamic ksize and strides with MaxPool and AvgPool #9514

Closed
wants to merge 3 commits into from

Conversation

yongtang
Copy link
Member

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 and AvgPoolV2 so that it is dynamic now. This fix also deprecates MaxPool and AvgPool.

This fix fixes #4746.

@tensorflow-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@yongtang yongtang mentioned this pull request Apr 28, 2017
@zheng-xq zheng-xq requested review from keveman and removed request for keveman May 1, 2017 20:09
@vrv vrv added the API review API Review label May 1, 2017
@vrv vrv requested a review from yzhwang May 1, 2017 21:04
@josh11b
Copy link
Contributor

josh11b commented May 1, 2017

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:
https://www.tensorflow.org/programmers_guide/data_versions#evolving_graphdef_versions and to support eventually deleting the first versions of these ops.

@josh11b josh11b removed the API review API Review label May 1, 2017
Copy link

@yzhwang yzhwang left a 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) {
Copy link

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) {
Copy link

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) {
Copy link

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) {
Copy link

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) {
Copy link

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?

Copy link
Member Author

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(
Copy link

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):
Copy link

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.

Copy link
Member Author

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.

@vrv vrv added the stat:awaiting response Status - Awaiting response from author label May 5, 2017
@tensorflow-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@rmlarsen
Copy link
Member

@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>
@yongtang
Copy link
Member Author

@rmlarsen @yzhwang The PR has been rebased and updated. Please take a look.

@rmlarsen
Copy link
Member

@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])
Copy link
Member

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?

@rmlarsen
Copy link
Member

@yongtang There are a number of test failures due to the changes, please address those.

@martinwicke martinwicke added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Jun 14, 2017
@martinwicke
Copy link
Member

I'll close this, as it appears inactive. Please create a new PR if you would like to pick this back up.

@hgaiser
Copy link
Contributor

hgaiser commented Jul 26, 2017

@yongtang is this still being worked on? It appears to be exactly what I need.

@yongtang
Copy link
Member Author

@hgaiser A new PR #11875 has been created to try to address the Jenkins test failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ksize in max_pool
9 participants