{"record":{"id":"dbe82a09afdbe7df","repo":"keras-team/keras","slug":"when-using-relative-bounding-box-formats-e-g-re","errorCode":null,"errorMessage":"When using relative bounding box formats (e.g. `rel_yxyx`) the `image_shape` argument must be provided.Received `image_shape`: {image_shape}","messagePattern":"When using relative bounding box formats \\(e\\.g\\. `rel_yxyx`\\) the `image_shape` argument must be provided\\.Received `image_shape`: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/iou.py","lineNumber":121,"sourceCode":"\n    if boxes1_rank not in [2, 3]:\n        raise ValueError(\n            \"compute_iou() expects boxes1 to be batched, or to be unbatched. \"\n            f\"Received len(boxes1.shape)={boxes1_rank}, \"\n            f\"len(boxes2.shape)={boxes2_rank}. Expected either \"\n            \"len(boxes1.shape)=2 AND or len(boxes1.shape)=3.\"\n        )\n    if boxes2_rank not in [2, 3]:\n        raise ValueError(\n            \"compute_iou() expects boxes2 to be batched, or to be unbatched. \"\n            f\"Received len(boxes1.shape)={boxes1_rank}, \"\n            f\"len(boxes2.shape)={boxes2_rank}. Expected either \"\n            \"len(boxes2.shape)=2 AND or len(boxes2.shape)=3.\"\n        )\n\n    target_format = \"yxyx\"\n    if \"rel\" in bounding_box_format and image_shape is None:\n        raise ValueError(\n            \"When using relative bounding box formats (e.g. `rel_yxyx`) \"\n            \"the `image_shape` argument must be provided.\"\n            f\"Received `image_shape`: {image_shape}\"\n        )\n\n    if image_shape is None:\n        height, width = None, None\n    else:\n        height, width, _ = image_shape\n\n    boxes1 = converters.convert_format(\n        boxes1,\n        source=bounding_box_format,\n        target=target_format,\n        height=height,\n        width=width,\n    )\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/iou.py#L103-L139","documentation":"compute_iou supports relative bounding box formats (any format containing 'rel', e.g. 'rel_xyxy', 'rel_yxyx'), but relative coordinates must be converted to absolute pixels internally, which requires the image dimensions. If bounding_box_format contains 'rel' and image_shape is None, this ValueError is raised.","triggerScenarios":"compute_iou(boxes1, boxes2, bounding_box_format=\"rel_xyxy\") with no image_shape argument, or with image_shape=None passed explicitly.","commonSituations":"Swapping a pipeline from absolute to normalized coordinates without threading the image size through; reusing an IoU call written for 'xyxy' after changing the format string.","solutions":["Pass image_shape, e.g. compute_iou(b1, b2, bounding_box_format=\"rel_xyxy\", image_shape=(H, W)).","Or convert boxes to an absolute format ('xyxy') and drop the rel format string."],"exampleFix":"# before\niou = compute_iou(b1, b2, bounding_box_format=\"rel_xyxy\")\n# after\niou = compute_iou(b1, b2, bounding_box_format=\"rel_xyxy\", image_shape=(416, 416))","handlingStrategy":"validation","validationCode":"if \"rel\" in bounding_box_format:\n    assert image_shape is not None, \"image_shape required for relative formats\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair a rel format with image_shape in one helper function so they cannot diverge."],"tags":["keras","bounding-boxes","iou","relative-coordinates","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}