{"record":{"id":"ce5751ce15d7935f","repo":"keras-team/keras","slug":"invalid-size-argument-expected-a-tuple-of-lengt","errorCode":null,"errorMessage":"Invalid `size` argument. Expected a tuple of length 2 or 3. Received: size={size} with length {len(size)}","messagePattern":"Invalid `size` argument\\. Expected a tuple of length 2 or 3\\. Received: size=(.+?) with length (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":734,"sourceCode":"    >>> patches = keras.ops.image.extract_patches(volumes, (3, 3, 3))\n    >>> patches.shape\n    (2, 3, 3, 3, 81)\n\n    >>> # 3D patches from single volume\n    >>> volume = np.random.random((10, 10, 10, 3)).astype(\"float32\")\n    >>> patches = keras.ops.image.extract_patches(volume, (3, 3, 3))\n    >>> patches.shape\n    (3, 3, 3, 81)\n    \"\"\"\n    # Validate size argument\n    if not isinstance(size, int):\n        if not isinstance(size, (tuple, list)):\n            raise TypeError(\n                \"Invalid `size` argument. Expected an int or a tuple. \"\n                f\"Received: size={size} of type {type(size).__name__}\"\n            )\n        if len(size) not in (2, 3):\n            raise ValueError(\n                \"Invalid `size` argument. Expected a tuple of length 2 or 3. \"\n                f\"Received: size={size} with length {len(size)}\"\n            )\n\n    # 2D patch extraction (default)\n    if any_symbolic_tensors((images,)):\n        return ExtractPatches(\n            size=size,\n            strides=strides,\n            dilation_rate=dilation_rate,\n            padding=padding,\n            data_format=data_format,\n        ).symbolic_call(images)\n\n    return _extract_patches(\n        images, size, strides, dilation_rate, padding, data_format=data_format\n    )\n","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L716-L752","documentation":"Guard in extract_patches: after size passed the int/tuple type check, its length is neither 2 (2D images) nor 3 (3D volumes), so the function cannot decide whether to route to the 2D or 3D patch-extraction implementation.","triggerScenarios":"Thrown at keras/src/ops/image.py:734 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a 2-element tuple for image patches, e.g. (3, 3)","Use a 3-element tuple for volume patches, e.g. (3, 3, 3)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}