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.keras.layers.MaxPooling3D crashes #51936

Closed
lugalUrim opened this issue Sep 10, 2021 · 7 comments · Fixed by #51975
Closed

tf.keras.layers.MaxPooling3D crashes #51936

lugalUrim opened this issue Sep 10, 2021 · 7 comments · Fixed by #51975
Assignees
Labels
2.6.0 comp:keras Keras related issues type:bug Bug

Comments

@lugalUrim
Copy link

System information

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

Describe the current behavior
tf.keras.layers.MaxPooling3D crashes when pool_size contains 0, and outputs a all-inf tensor when pool_size contains negative values.

Describe the expected behavior
Expect a ValueError to be thrown if the input pool_size contains zero or negative values.

Standalone code to reproduce the issue
If the pool_size has 0:

import tensorflow as tf
pool_size = [2, 2, 0]
layer = tf.keras.layers.MaxPooling3D(strides=1, pool_size=pool_size)
input_tensor = tf.random.uniform([3, 4, 10, 11, 12], dtype=tf.float32)
res = layer(input_tensor) # crash

Outputs:

Floating point exception (core dumped)

If the pool_size has negative values:

import tensorflow as tf
pool_size = [2, 2, -2]
layer = tf.keras.layers.MaxPooling3D(strides=1, pool_size=pool_size,)
input_tensor = tf.random.uniform([3, 4, 10, 11, 12], dtype=tf.float32)
res = layer(input_tensor)
print(res)

The output is a tensor with shape=(3, 3, 9, 14, 12) and all inf values.

@lugalUrim
Copy link
Author

It turns out that tf.keras.layers.AveragePooling3D also crashes when pool_size contains 0.

@sushreebarsa sushreebarsa added 2.6.0 comp:keras Keras related issues labels Sep 12, 2021
@sushreebarsa
Copy link
Contributor

@WingsBrokenAngel
Copy link

Hi, I have created a PR for Keras to solve this issue.

@yongtang
Copy link
Member

While the original issue is coming from tf.keras.layers.MaxPooling3D, the issue is triggered when max_pool3d is called directly with tensorflow itself. For that PR #51975 has been created to fix the issue inside tensorflow.

@sushreebarsa sushreebarsa removed the stat:awaiting response Status - Awaiting response from author label Sep 13, 2021
@lugalUrim
Copy link
Author

Thanks for the information @sushreebarsa, I will post new issues in the keras repo, but I guess we can keep this issue in tensorflow, as mentioned by @yongtang there are related bugs in the tensorflow operator implementations as well.

@lugalUrim
Copy link
Author

Thank you @WingsBrokenAngel and @yongtang for your PRs! Actually here are more crash bugs I find when pool_size/k_size <= 0, so we may want to fix all of these in the codebase and also cover them in the unit tests.

  • tf.keras.layers.AveragePooling1D, tf.keras.layers.AveragePooling2D, tf.keras.layers.AveragePooling3D
  • tf.keras.layers.MaxPooling1D, tf.keras.layers.MaxPooling2D, tf.keras.layers.MaxPooling3D
  • tf.nn.avg_pool1d, tf.nn.avg_pool2d, tf.nn.avg_pool3d
  • tf.nn.max_pool1d, tf.nn.max_pool2d, tf.nn.max_pool3d

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.6.0 comp:keras Keras related issues type:bug Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants