keras-team/keras · error · ValueError
Invalid images dtype: expected float dtype. Received…
Error message
Invalid images dtype: expected float dtype. Received: images.dtype={dtype} What it means
Dtype guard in `rgb_to_hsv` (NumPy backend): the HSV conversion math uses fractional arithmetic that is only meaningful for floating-point inputs. After standardizing the image's dtype, the guard rejects integer (or other non-float) images with this error naming the offending dtype; note the final result is cast back to the original dtype, so integer precision is preserved only for float inputs.
Solutions
- Convert images to a float dtype first: keras.ops.cast(images, 'float32')
- Cast to the working precision used elsewhere in the pipeline (e.g. keras.ops.cast(images, keras.config.floatx()))
- Ensure upstream preprocessing (loading, augmentation) produces float tensors rather than uint8
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/image.py:89 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/6c9d329e16c0235f.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/ops/image.py:89
grayscales = np.tensordot(images, rgb_weights, axes=(channels_axis, -1))
grayscales = np.expand_dims(grayscales, axis=channels_axis)
return grayscales.astype(original_dtype)
def rgb_to_hsv(images, data_format=None):
# Ref: dm_pix
images = convert_to_tensor(images)
dtype = backend.standardize_dtype(images.dtype)
data_format = standardize_data_format(data_format)
channels_axis = -1 if data_format == "channels_last" else -3
if len(images.shape) not in (3, 4):
raise ValueError(
"Invalid images rank: expected rank 3 (single image) "
"or rank 4 (batch of images). Received input with shape: "
f"images.shape={images.shape}"
)
if not backend.is_float_dtype(dtype):
raise ValueError(
"Invalid images dtype: expected float dtype. "
f"Received: images.dtype={dtype}"
)
eps = ml_dtypes.finfo(dtype).eps
images = np.where(np.abs(images) < eps, 0.0, images)
red, green, blue = np.split(images, 3, channels_axis)
red = np.squeeze(red, channels_axis)
green = np.squeeze(green, channels_axis)
blue = np.squeeze(blue, channels_axis)
def rgb_planes_to_hsv_planes(r, g, b):
value = np.maximum(np.maximum(r, g), b)
minimum = np.minimum(np.minimum(r, g), b)
range_ = value - minimum
safe_value = np.where(value > 0, value, 1.0)
safe_range = np.where(range_ > 0, range_, 1.0)
View on GitHub (pinned to 7a34a03db6)