{"record":{"id":"c043dd61ab0de8cd","repo":"keras-team/keras","slug":"size-must-have-positive-height-and-width-receiv","errorCode":null,"errorMessage":"`size` must have positive height and width. Received: size={size}","messagePattern":"`size` must have positive height and width\\. Received: size=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":366,"sourceCode":"    >>> 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` \"\n            \"can be `True`.\"\n        )\n    if any_symbolic_tensors((images,)):\n        return Resize(\n            size,\n            interpolation=interpolation,\n            antialias=antialias,","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L348-L384","documentation":"resize rejects size tuples whose height or width entries are statically-known ints <= 0. Zero or negative dimensions cannot form a valid output image.","triggerScenarios":"Calling resize with size=(0, 224), (-1, -1), or values computed from a config/env variable that defaults to 0; dynamic tensor sizes pass through since only int entries are checked.","commonSituations":"Reading target resolution from a config where height/width keys are absent and default to 0; computing size as target_size - padding with an off-by error going negative.","solutions":["Fix the size computation so both entries are positive ints","Validate config-derived sizes at startup: assert size[0] > 0 and size[1] > 0"],"exampleFix":"# before\nsize = (cfg.height, cfg.width)  # cfg.width missing -> 0\ny = keras.ops.image.resize(x, size)\n\n# after\nsize = (cfg.height or 224, cfg.width or 224)\ny = keras.ops.image.resize(x, size)","handlingStrategy":"validation","validationCode":"h, w = size\nassert isinstance(h, int) and h > 0 and isinstance(w, int) and w > 0","typeGuard":"def is_positive_size(size) -> bool:\n    return all(isinstance(v, int) and v > 0 for v in size)","tryCatchPattern":null,"preventionTips":["Default config resolutions to real values, not 0","Validate derived sizes after arithmetic that can go non-positive"],"tags":["keras","image","resize","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}