{"record":{"id":"a3e3212af9b70d7f","repo":"keras-team/keras","slug":"only-one-of-pad-to-aspect-ratio-crop-to-aspec-a3e321","errorCode":null,"errorMessage":"Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` can be `True`.","messagePattern":"Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` can be `True`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":376,"sourceCode":"    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,\n            data_format=data_format,\n            crop_to_aspect_ratio=crop_to_aspect_ratio,\n            pad_to_aspect_ratio=pad_to_aspect_ratio,\n            fill_mode=fill_mode,\n            fill_value=fill_value,\n        ).symbolic_call(images)\n    return _resize(\n        images,\n        size,\n        interpolation=interpolation,","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L358-L394","documentation":"resize supports only one aspect-ratio strategy at a time. Setting both pad_to_aspect_ratio=True and crop_to_aspect_ratio=True is contradictory (pad keeps whole image with fill, crop discards edges) and raises this ValueError.","triggerScenarios":"Calling keras.ops.image.resize(x, size, pad_to_aspect_ratio=True, crop_to_aspect_ratio=True); forwarding **kwargs from a config/augmentation preset that sets both flags.","commonSituations":"Augmentation search spaces or config files where both options default on; merging config presets that each enable a different strategy.","solutions":["Choose one flag: pad_to_aspect_ratio=True (keeps full content, adds fill_value) OR crop_to_aspect_ratio=True (center-crops)","Sanitize user/config kwargs: assert not (kw.get('pad_to_aspect_ratio') and kw.get('crop_to_aspect_ratio'))"],"exampleFix":"# before\ny = keras.ops.image.resize(x, (224,224), pad_to_aspect_ratio=True, crop_to_aspect_ratio=True)\n\n# after\ny = keras.ops.image.resize(x, (224,224), pad_to_aspect_ratio=True)","handlingStrategy":"validation","validationCode":"assert not (pad_to_aspect_ratio and crop_to_aspect_ratio)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one aspect-ratio strategy per pipeline and encode it in one config key","Sanitize aug kwargs before forwarding to resize"],"tags":["keras","image","resize","argument-validation","config"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}