{"record":{"id":"2a44c5f2a2c97cd2","repo":"keras-team/keras","slug":"expected-size-to-be-a-tuple-of-2-integers-recei","errorCode":null,"errorMessage":"Expected `size` to be a tuple of 2 integers. Received: size={size}","messagePattern":"Expected `size` to be a tuple of 2 integers\\. Received: size=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":359,"sourceCode":"\n    >>> x = np.random.random((2, 4, 4, 3)) # batch of 2 RGB images\n    >>> y = keras.ops.image.resize(x, (2, 2))\n    >>> y.shape\n    (2, 2, 2, 3)\n\n    >>> x = np.random.random((4, 4, 3)) # single RGB image\n    >>> y = keras.ops.image.resize(x, (2, 2))\n    >>> y.shape\n    (2, 2, 3)\n\n    >>> x = np.random.random((2, 3, 4, 4)) # batch of 2 RGB images\n    >>> y = keras.ops.image.resize(x, (2, 2),\n    ...     data_format=\"channels_first\")\n    >>> y.shape\n    (2, 3, 2, 2)\n    \"\"\"\n    if len(size) != 2:\n        raise ValueError(\n            \"Expected `size` to be a tuple of 2 integers. \"\n            f\"Received: size={size}\"\n        )\n    if (isinstance(size[0], int) and size[0] <= 0) or (\n        isinstance(size[1], int) and size[1] <= 0\n    ):\n        raise ValueError(\n            f\"`size` must have positive height and width. Received: size={size}\"\n        )\n    if len(images.shape) < 3 or len(images.shape) > 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 pad_to_aspect_ratio and crop_to_aspect_ratio:\n        raise ValueError(\n            \"Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` \"","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L341-L377","documentation":"keras.ops.image.resize requires size to be exactly a 2-element sequence (height, width). Passing an int, a 3-tuple, a nested list, or an empty sequence raises this ValueError before any resizing.","triggerScenarios":"Calling resize(images, 224); resize(images, (224, 224, 3)) (including channels); passing the output shape of another op that has 3+ entries.","commonSituations":"Confusing target size with full output shape including channels; passing a config value parsed as int; chaining ops where .shape slices are the wrong length.","solutions":["Pass exactly two values: resize(images, (224, 224))","If your target came as a full shape, slice it: resize(images, shape[:-1]) for channels_last or shape[1:3] as appropriate"],"exampleFix":"# before\ny = keras.ops.image.resize(x, (224, 224, 3))\n\n# after\ny = keras.ops.image.resize(x, (224, 224))","handlingStrategy":"type-guard","validationCode":"size = tuple(size)\nassert len(size) == 2, f'size must have 2 entries, got {size!r}'","typeGuard":"def is_valid_resize_size(size) -> bool:\n    try:\n        s = tuple(size)\n    except TypeError:\n        return False\n    return len(s) == 2","tryCatchPattern":null,"preventionTips":["Never include channels in resize size","Store target resolution as a (h, w) tuple in configs"],"tags":["keras","image","resize","argument-validation"],"backgroundTag":"invalid-argument-shape","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}