{"record":{"id":"0af959988f19cb12","repo":"keras-team/keras","slug":"invalid-images-dtype-expected-float-dtype-receiv-0af959","errorCode":null,"errorMessage":"Invalid images dtype: expected float dtype. Received: images.dtype={dtype}","messagePattern":"Invalid images dtype: expected float dtype\\. Received: images\\.dtype=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":101,"sourceCode":"class RGBToHSV(Operation):\n    def __init__(self, data_format=None, *, name=None):\n        super().__init__(name=name)\n        self.data_format = backend.standardize_data_format(data_format)\n\n    def call(self, images):\n        return backend.image.rgb_to_hsv(images, data_format=self.data_format)\n\n    def compute_output_spec(self, images):\n        images_shape = list(images.shape)\n        dtype = images.dtype\n        if len(images_shape) not in (3, 4):\n            raise ValueError(\n                \"Invalid images rank: expected rank 3 (single image) \"\n                \"or rank 4 (batch of images). \"\n                f\"Received: images.shape={images_shape}\"\n            )\n        if not backend.is_float_dtype(dtype):\n            raise ValueError(\n                \"Invalid images dtype: expected float dtype. \"\n                f\"Received: images.dtype={dtype}\"\n            )\n        channels_axis = -1 if self.data_format == \"channels_last\" else -3\n        channels = images_shape[channels_axis]\n        if channels is not None and channels != 3:\n            raise ValueError(\n                \"Input images must have 3 channels, but received images with \"\n                f\"{channels} channels.\"\n            )\n        return KerasTensor(shape=images_shape, dtype=images.dtype)\n\n\n@keras_export(\"keras.ops.image.rgb_to_hsv\")\ndef rgb_to_hsv(images, data_format=None):\n    \"\"\"Convert RGB images to HSV.\n\n    `images` must be of float dtype, and the output is only well defined if the","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L83-L119","documentation":"rgb_to_hsv mathematically requires fractional values, so its compute_output_spec verifies images.dtype is a float dtype (float16/32/64, bfloat16). Integer image arrays (uint8, int32) are rejected with this ValueError.","triggerScenarios":"Passing uint8-loaded images (np.array(Image.open(...)) or cv2.imread output) directly to keras.ops.image.rgb_to_hsv.","commonSituations":"Forgetting the standard /255.0 normalization step; mixing OpenCV uint8 pipelines with Keras float ops; loading with image_dataset_from_directory without a rescale layer having been applied yet.","solutions":["Convert and normalize first: images = images.astype('float32') / 255.0","Use keras.layers.Rescaling(1./255) as the first layer of your model instead"],"exampleFix":"# before\nhsv = keras.ops.image.rgb_to_hsv(img_uint8)  # uint8 -> ValueError\n\n# after\nimg = img_uint8.astype('float32') / 255.0\nhsv = keras.ops.image.rgb_to_hsv(img)","handlingStrategy":"validation","validationCode":"assert images.dtype in ('float16','float32','float64','bfloat16') or str(images.dtype).startswith('float')","typeGuard":"def is_float_tensor(x) -> bool:\n    return str(getattr(x, 'dtype', '')).startswith('float') or 'bfloat16' in str(getattr(x, 'dtype', ''))","tryCatchPattern":null,"preventionTips":["Put keras.layers.Rescaling(1./255) first in image models","Convert with .astype('float32') / 255.0 as a fixed loading step"],"tags":["keras","image","dtype-validation","rgb-to-hsv"],"backgroundTag":"dtype-validation","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}