You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tf.nn.conv2d terminates process with invalid input shape instead of raising an exception #77336
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
2.17.0
Custom code
Yes
OS platform and distribution
Linux Ubuntu 22.04.3 LTS
Mobile device
No response
Python version
3.11.9
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
TensorFlow terminates the process when passing an invalid input shape to tf.nn.conv2d. Instead of raising a Python exception that can be caught with a try-except block.
I expected TensorFlow to raise a catchable Python exception indicating that the input tensor shape is invalid. This would allow the error to be handled in a try-except block, instead of terminating the process. The error message should clearly explain the shape mismatch issue.
2024-10-09 14:53:31.118589: F ./tensorflow/core/util/tensor_format.h:427] Check failed: index >= 0 && index < num_total_dims Invalid index from the dimension: 3, 0, C Aborted (core dumped)
Kernel Tensor: Similarly, the kernel must be reshaped into [filter_height, filter_width, input_channels, output_channels]. For a 2x2 kernel, this can be done as follows:
Kernel Tensor: Similarly, the kernel must be reshaped into [filter_height, filter_width, input_channels, output_channels]. For a 2x2 kernel, this can be done as follows:
By reshaping both the input and kernel to their required 4D shapes, the convolution operation can be performed without errors.
Here is the link of the colab in which i tried, and the it wasn't throwing any errors here
let me know if it helps in your issue
Thank you for your suggestion! Reshaping the input and kernel tensors to 4D indeed resolves the issue for this specific case. However, my concern is more about TensorFlow's robustness. Ideally, when passing invalid input shapes to tf.nn.conv2d, TensorFlow should raise a catchable Python exception (e.g., ValueError or TypeError) rather than terminating the process. This would allow for better error handling without the program crashing.
Let me know if this makes sense, and thank you again for your help!
You're very right. Currently, TensorFlow's behavior of terminating the process with a non-catchable error (rather than raising a Python exception like ValueError or TypeError) prevents graceful error handling. A more robust approach would be to throw a catchable Python exception that informs the user of invalid tensor shapes without crashing the entire program. i think you should tag someone from their team
@LegendBug,
I tried to execute the mentioned code on tensorflow v2.17 & tf-nightly and observed that it was providing the error convolution input must be 4-dimensional: [1,1,3] [Op:Conv2D] rather than the crash/abort. Kindly find the gist of it here and confirm whether you are also facing the same. Thank you!
@LegendBug, I tried to execute the mentioned code on tensorflow v2.17 & tf-nightly and observed that it was providing the error convolution input must be 4-dimensional: [1,1,3] [Op:Conv2D] rather than the crash/abort. Kindly find the gist of it here and confirm whether you are also facing the same. Thank you!
Thank you for your response.
Using Colab's built-in configuration (CPU + Python 3), I indeed observed the expected error message. However, when I connect Colab to my local device, the program still crashes unexpectedly.
You can see my Colab runtime records here. I attempted to run two similar programs—the first one produced output normally, while the second one caused a crash. Since Colab seems to disconnect sessions on crashes, the output is not complete, attached is my complete output at runtime locally. output.log
Please let me know if there's any additional information needed. Thank you again for your assistance!
Hi @LegendBug,
Thank you so much for filing this issue! We truly appreciate your support. At the moment, this request is not prioritized and mark it for community contributions. If you would like to contribute on a fix, please feel free to fork the repository and submit a pull request in accordance with the TensorFlow CONTRIBUTION GUIDELINES and link this issue in your PR to ensure the maintainers can easily review and collaborate.
To avoid duplicate work, please leave a comment here if you decide to take it on!
Thank you again for your interest and we look forward to seeing your contributions!
Hi @LegendBug ,
Thank you for raising your concern here.
A fix for this issue has been proposed in this #128598. Once it is merged, this issue will be resolved.
Hi @bodapatisaikrishna ,
Thank you for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
Activity
AdvaitDongre commentedon Oct 9, 2024
To resolve this issue, the input tensor and kernel must be reshaped into 4D tensors:
Input Tensor: The input must be reshaped into
[batch_size, height, width, channels]format. For a 1x3 input, this can be done using:Kernel Tensor: Similarly, the kernel must be reshaped into
[filter_height, filter_width, input_channels, output_channels]. For a 2x2 kernel, this can be done as follows:By reshaping both the input and kernel to their required 4D shapes, the convolution operation can be performed without errors.
Here is the link of the colab in which i tried, and the it wasn't throwing any errors here
let me know if it helps in your issue
LegendBug commentedon Oct 9, 2024
Thank you for your suggestion! Reshaping the input and kernel tensors to 4D indeed resolves the issue for this specific case. However, my concern is more about TensorFlow's robustness. Ideally, when passing invalid input shapes to tf.nn.conv2d, TensorFlow should raise a catchable Python exception (e.g., ValueError or TypeError) rather than terminating the process. This would allow for better error handling without the program crashing.
Let me know if this makes sense, and thank you again for your help!
AdvaitDongre commentedon Oct 9, 2024
You're very right. Currently, TensorFlow's behavior of terminating the process with a non-catchable error (rather than raising a Python exception like ValueError or TypeError) prevents graceful error handling. A more robust approach would be to throw a catchable Python exception that informs the user of invalid tensor shapes without crashing the entire program. i think you should tag someone from their team
tilakrayal commentedon Oct 17, 2024
@LegendBug,
I tried to execute the mentioned code on tensorflow v2.17 & tf-nightly and observed that it was providing the error convolution input must be 4-dimensional: [1,1,3] [Op:Conv2D] rather than the crash/abort. Kindly find the gist of it here and confirm whether you are also facing the same. Thank you!
LegendBug commentedon Oct 17, 2024
Thank you for your response.
Using Colab's built-in configuration (CPU + Python 3), I indeed observed the expected error message. However, when I connect Colab to my local device, the program still crashes unexpectedly.
You can see my Colab runtime records here. I attempted to run two similar programs—the first one produced output normally, while the second one caused a crash. Since Colab seems to disconnect sessions on crashes, the output is not complete, attached is my complete output at runtime locally.
output.log
Please let me know if there's any additional information needed. Thank you again for your assistance!
Kayyuri commentedon Jun 1, 2026
Hi @LegendBug,
Thank you so much for filing this issue! We truly appreciate your support. At the moment, this request is not prioritized and mark it for community contributions. If you would like to contribute on a fix, please feel free to fork the repository and submit a pull request in accordance with the TensorFlow CONTRIBUTION GUIDELINES and link this issue in your PR to ensure the maintainers can easily review and collaborate.
To avoid duplicate work, please leave a comment here if you decide to take it on!
Thank you again for your interest and we look forward to seeing your contributions!
Venkat6871 commentedon Oct 9, 2026
Hi @LegendBug ,
Thank you for raising your concern here.
A fix for this issue has been proposed in this #128598. Once it is merged, this issue will be resolved.
Hi @bodapatisaikrishna ,
Thank you for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
google-ml-butler commentedon Oct 9, 2026
Are you satisfied with the resolution of your issue?
Yes
No
Validate input and filter ranks in tf.nn.conv2d