#63067·tensorflow

`tf.raw_ops.ExtractImagePatches`: Assertion failure in shape inference step

Author: Sehun0819Created Feb 27, 2024Updated Oct 1, 2026
Labelstype:bugcomp:opscomp:coreawaiting PR merge

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tf 2.17

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04 LTS

Mobile device

No response

Python version

3.11.7

Bazel version

6.5.0

GCC/compiler version

clang 16

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

tf.raw_ops.ExtractImagePatches can lead to assertion failure in shape inference step. Error location is here:

cpp
      TF_RETURN_IF_ERROR(c->Multiply(
          c->Dim(input_shape, 3), ksize_rows * ksize_cols, &output_depth_dim));

Because it does not check validity of ksize_rows * ksize_cols, the negative value of it is fed to Multiply:

cpp
Status InferenceContext::Multiply(DimensionHandle first,
                                  DimensionOrConstant second,
                                  DimensionHandle* out)

And it ends up with assertion failure at a constructor of DimensionOrConstant.

Standalone code to reproduce the issue

python
import tensorflow as tf

tf.compat.v1.disable_eager_execution()

tf.raw_ops.ExtractImagePatches(
    images=tf.random.normal([1,1,1,1]),
    ksizes=[1,-1,2,1],
    strides=[1,1,1,1],
    rates=[1,1,1,1],
    padding="VALID",
    name=None
)

Relevant log output

Release build: Outputs nothing

Debug build:

bash
2024-02-27 20:05:58.701202: F ./tensorflow/core/framework/shape_inference.h:891] Check failed: val >= 0 || val == InferenceContext::kUnknownDim Dimension must be non-negative or equal to InferenceContext::kUnknownDim but got -2
Aborted (core dumped)