{"record":{"id":"c9b4acef74964d27","repo":"keras-team/keras","slug":"name-must-be-0-received-name-value","errorCode":null,"errorMessage":"{name} must be >= 0. Received: {name}={value}","messagePattern":"(.+?) must be >= 0\\. Received: (.+?)=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":1536,"sourceCode":"    \"\"\"\n    if any_symbolic_tensors((inputs, coordinates)):\n        return MapCoordinates(\n            order,\n            fill_mode,\n            fill_value,\n        ).symbolic_call(inputs, coordinates)\n    return backend.image.map_coordinates(\n        inputs,\n        coordinates,\n        order,\n        fill_mode,\n        fill_value,\n    )\n\n\ndef _validate_non_negative(value, name):\n    if value is not None and value < 0:\n        raise ValueError(f\"{name} must be >= 0. Received: {name}={value}\")\n\n\ndef _validate_pad_images_args(\n    top_padding,\n    left_padding,\n    bottom_padding,\n    right_padding,\n    target_height,\n    target_width,\n):\n    if [top_padding, bottom_padding, target_height].count(None) != 1:\n        raise ValueError(\n            \"Must specify exactly two of \"\n            \"top_padding, bottom_padding, target_height. \"\n            f\"Received: top_padding={top_padding}, \"\n            f\"bottom_padding={bottom_padding}, \"\n            f\"target_height={target_height}\"\n        )","sourceCodeStart":1518,"sourceCodeEnd":1554,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L1518-L1554","documentation":"Shared validator for the pad/crop images ops: any explicitly supplied padding/cropping amount (or related numeric arg) must be non-negative. A negative value is rejected before any tensor op because negative padding/cropping is undefined.","triggerScenarios":"keras.ops.image.pad_images / crop_images (or the corresponding layers) with a negative top/bottom/left/right padding or cropping value, e.g. top_padding=-4, often computed as target - height - other_side and going negative.","commonSituations":"Using negative padding to emulate cropping; target_height smaller than the image so derived padding becomes negative; arithmetic on config values that can go below zero for some samples in a pipeline.","solutions":["Use crop_images to shrink, pad_images to grow — never negative pad values","If deriving padding from target sizes, clamp: max(0, target - height - other) or switch to specifying target sizes directly","Validate all padding/cropping args against 0 before the call"],"exampleFix":"# before\npad_images(img, top_padding=height - target_height, ...)  # negative\n\n# after\ncrop_images(img, top_cropping=target_height - height if False else 0, ...)  # or just:\npad_images(img, target_height=target_h, target_width=target_w, ...)  # derive non-negative pads","handlingStrategy":"validation","validationCode":"for name, v in [('top_padding', top_padding), ...]:\n    if v is not None and v < 0:\n        raise ValueError(f'{name} must be >= 0')","typeGuard":"def all_non_negative(vals) -> bool:\n    return all(v is None or v >= 0 for v in vals)","tryCatchPattern":null,"preventionTips":["Clamp derived paddings with max(0, x)","Use crop to shrink, pad to grow"],"tags":["keras","image","padding","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}