Description: The reproduction clearly shows inconsistent behavior for the same API call: eager execution correctly errors on a 4-channel tensor with data_format='channels_first', while the Keras Input placeholder path accepts it and returns a symbolic output shape instead of validating the channel count. This strongly indicates a real shape/validation bug in the static path.
Summary
keras.ops.image.rgb_to_hsv() behaves inconsistently for data_format="channels_first": eager tensors are rejected when the input does not have 3 channels, but a keras.Input placeholder is accepted and produces a symbolic output shape.
Reproduction
import keras
import numpy as np
import tensorflow as tf
import numpy as np
import keras
from keras import ops
def call_func(inputs, data_format=None):
return keras.ops.image.rgb_to_hsv(images=inputs, data_format=data_format)
# Create test input
test_input = np.random.random((4, 4, 3)).astype(np.float32)
# Test with eager tensor (dynamic)
print("Testing with eager tensor:")
try:
dynamic_result = call_func(test_input, data_format="channels_first")
print(f"Dynamic output shape: {dynamic_result.shape}")
except Exception as e:
print(f"Dynamic execution error: {e}")
# Test with Keras.Input placeholder (static)
print("\nTesting with Keras.Input placeholder:")
try:
placeholder_input = keras.Input(shape=(4, 3), dtype='float32')
static_result = call_func(placeholder_input, data_format="channels_first")
print(f"Static output shape: {static_result.shape}")
except Exception as e:
print(f"Static execution error: {e}")
print(f"\nInput shape: {test_input.shape}")
print(f"Data format: channels_first")
Colab link : https://colab.research.google.com/drive/1lsdB_CDC5N0dyHylS7IHvK391-tXSKhe?usp=sharing
Expected
Both eager and symbolic inputs should validate the channel dimension and raise an error unless the input has 3 channels for channels_first.
Actual
- Eager tensor:
input must have 3 channels but input only has 4 channels
keras.Input placeholder: returns output shape (None, 4, 3) without raising an error
Testing with eager tensor:
Dynamic execution error: {{function_node __wrapped__RGBToHSV_device_/job:localhost/replica:0/task:0/device:CPU:0}} input must have 3 channels but input only has 4 channels. [Op:RGBToHSV] name:
Testing with Keras.Input placeholder:
Static output shape: (None, 4, 3)
Input shape: (4, 4, 3)
Data format: channels_first
Description: The reproduction clearly shows inconsistent behavior for the same API call: eager execution correctly errors on a 4-channel tensor with
data_format='channels_first', while the Keras Input placeholder path accepts it and returns a symbolic output shape instead of validating the channel count. This strongly indicates a real shape/validation bug in the static path.Summary
keras.ops.image.rgb_to_hsv()behaves inconsistently fordata_format="channels_first": eager tensors are rejected when the input does not have 3 channels, but akeras.Inputplaceholder is accepted and produces a symbolic output shape.Reproduction
Colab link : https://colab.research.google.com/drive/1lsdB_CDC5N0dyHylS7IHvK391-tXSKhe?usp=sharing
Expected
Both eager and symbolic inputs should validate the channel dimension and raise an error unless the input has 3 channels for
channels_first.Actual
input must have 3 channels but input only has 4 channelskeras.Inputplaceholder: returns output shape(None, 4, 3)without raising an error