{"record":{"id":"814148b972045575","repo":"keras-team/keras","slug":"invalid-images-rank-expected-rank-3-single-image-814148","errorCode":null,"errorMessage":"Invalid images rank: expected rank 3 (single image) or rank 4 (batch of images). Received input with shape: images.shape={images.shape}","messagePattern":"Invalid images rank: expected rank 3 \\(single image\\) or rank 4 \\(batch of images\\)\\. Received input with shape: images\\.shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/ops/image.py","lineNumber":52,"sourceCode":"}\nSCALE_AND_TRANSLATE_METHODS = {\n    \"linear\",\n    \"bilinear\",\n    \"trilinear\",\n    \"cubic\",\n    \"bicubic\",\n    \"tricubic\",\n    \"lanczos3\",\n    \"lanczos5\",\n}\n\n\ndef rgb_to_grayscale(images, data_format=None):\n    images = convert_to_tensor(images)\n    data_format = standardize_data_format(data_format)\n    channels_axis = -1 if data_format == \"channels_last\" else -3\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). Received input with shape: \"\n            f\"images.shape={images.shape}\"\n        )\n    if images.shape[channels_axis] not in (1, 3):\n        raise ValueError(\n            \"Invalid channel size: expected 3 (RGB) or 1 (Grayscale). \"\n            f\"Received input with shape: images.shape={images.shape}\"\n        )\n    if images.shape[channels_axis] == 1:\n        return images.copy()\n    # Convert to floats\n    original_dtype = images.dtype\n    compute_dtype = backend.result_type(images.dtype, float)\n    images = images.astype(compute_dtype)\n\n    # Ref: tf.image.rgb_to_grayscale\n    rgb_weights = np.array([0.2989, 0.5870, 0.1140], dtype=images.dtype)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/ops/image.py#L34-L70","documentation":"Error \"Invalid images rank: expected rank 3 (single image) or rank 4 (batch of images). Received input with shape: images.shape={images.shape}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/numpy/ops/image.py:52 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}