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

tf.nn.max_pool2d: No support for tf.Tensor input for ksize #42973

Open
luuzk opened this issue Sep 4, 2020 · 7 comments
Open

tf.nn.max_pool2d: No support for tf.Tensor input for ksize #42973

luuzk opened this issue Sep 4, 2020 · 7 comments
Assignees
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.11 Issues related to TF 2.11 type:bug Bug

Comments

@luuzk
Copy link

luuzk commented Sep 4, 2020

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10.0.19041
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: -
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.3.0
  • Python version: 3.7.6
  • Bazel version (if compiling from source): -
  • GCC/Compiler version (if compiling from source): -
  • CUDA/cuDNN version: 11.0/7.6.5
  • GPU model and memory: RTX 2070 8GB

Describe the current behavior
The ksize arguement of tf.nn.max_pool2d supports only native Python int but not tf.Tensor. This is not a problem when using eager mode, but very disadvantageous when calculating the ksize as a Tensor in TF Graph mode.

TypeError: Expected int for argument 'ksize' not <tf.Tensor 'random_uniform:0' shape=() dtype=int32>.

Describe the expected behavior
Tensor support for tf.nn.max_pool2d function parameters, espacially ksize.

Standalone code to reproduce the issue

@tf.function
def issue():
    inp = tf.convert_to_tensor(np.arange(75).reshape((1, 5, 5, 3)))
    ksize = tf.random.uniform([], 1, 3, dtype=tf.int32)
    return tf.nn.max_pool2d(inp, [ksize], 1, "SAME")

if __name__ == "__main__":
    issue()

Other info / logs
traceback.txt

Thank you in advance!

@bhack
Copy link
Contributor

bhack commented Sep 5, 2020

Check https://stackoverflow.com/questions/43574076/tensorflow-maxpool-with-dynamic-ksize
And #4746

@Shreerama9

This comment has been minimized.

@ravikyram ravikyram added comp:apis Highlevel API related issues TF 2.3 Issues related to TF 2.3 stat:awaiting response Status - Awaiting response from author labels Sep 6, 2020
@luuzk
Copy link
Author

luuzk commented Sep 7, 2020

Thank you @bhack! There seems to be a solution for this issue provided by PR #11875. Use gen_nn_ops.max_pool_v2 instead of gen_nn_ops.max_pool, which is used by default when calling tf.nn.max_pool2d. Change the code above to:

from tensorflow.python.ops import gen_nn_ops
return gen_nn_ops.max_pool_v2(inp, [1, ksize, ksize, 1], [1, 1, 1, 1], "SAME")

PR #14983 tries to integrate the utilization of gen_nn_ops.max_pool_v2 as standard behavior but was reverted. @yongtang @rmlarsen, are you interested to push PR #14983 into tensorflow:master to completely solve this issue, #1967 and, #4746?

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Sep 9, 2020
@ravikyram ravikyram assigned gowthamkpr and unassigned ravikyram Sep 16, 2020
@gowthamkpr gowthamkpr assigned rmlarsen and unassigned gowthamkpr Sep 17, 2020
@gowthamkpr gowthamkpr added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Sep 17, 2020
@sachinprasadhs
Copy link
Contributor

Was able to reproduce your issue in Tensorflow 2.5 version, please find the gist here. Thanks!

@cl886699
Copy link

cl886699 commented Jul 7, 2021

from tensorflow.python.ops import gen_nn_ops
return gen_nn_ops.max_pool_v2(inp, [1, ksize, ksize, 1], [1, 1, 1, 1], "SAME")

this is not working for me

@chunduriv chunduriv self-assigned this Mar 1, 2022
@chunduriv
Copy link
Contributor

chunduriv commented Mar 1, 2022

Was able to reproduce your issue in Tensorflow 2.11 version, please find the gist here. Thanks!

@chunduriv chunduriv added TF 2.8 and removed TF 2.3 Issues related to TF 2.3 labels Mar 1, 2022
@bhack
Copy link
Contributor

bhack commented Mar 1, 2022

/cc @rmlarsen @yongtang

@chunduriv chunduriv removed their assignment Mar 11, 2022
@pjpratik pjpratik added TF 2.11 Issues related to TF 2.11 and removed TF 2.8 labels Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.11 Issues related to TF 2.11 type:bug Bug
Projects
None yet
Development

No branches or pull requests