{"record":{"id":"e95d75ebc4eb19e7","repo":"keras-team/keras","slug":"height-and-width-must-be-set-if-format-xyxy","errorCode":null,"errorMessage":"`height` and `width` must be set if `format='xyxy'`.","messagePattern":"`height` and `width` must be set if `format='xyxy'`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py","lineNumber":116,"sourceCode":"        if source.startswith(\"rel_\") and target.startswith(\"rel_\"):\n            source = source.replace(\"rel_\", \"\", 1)\n            target = target.replace(\"rel_\", \"\", 1)\n        to_xyxy_converter = to_xyxy_converters[source]\n        from_xyxy_converter = from_xyxy_converters[target]\n        in_xyxy_boxes = to_xyxy_converter(boxes, height, width)\n        return from_xyxy_converter(in_xyxy_boxes, height, width)\n\n    def clip_to_image_size(\n        self,\n        bounding_boxes,\n        height=None,\n        width=None,\n        bounding_box_format=\"xyxy\",\n    ):\n        if bounding_box_format not in (\"xyxy\", \"rel_xyxy\"):\n            raise NotImplementedError\n        if bounding_box_format == \"xyxy\" and (height is None or width is None):\n            raise ValueError(\n                \"`height` and `width` must be set if `format='xyxy'`.\"\n            )\n\n        ops = self.backend\n        boxes = bounding_boxes[\"boxes\"]\n        labels = bounding_boxes.get(\"labels\", None)\n        if width is not None:\n            width = ops.cast(width, boxes.dtype)\n        if height is not None:\n            height = ops.cast(height, boxes.dtype)\n\n        if bounding_box_format == \"xyxy\":\n            x1, y1, x2, y2 = ops.numpy.split(boxes, 4, axis=-1)\n            x1 = ops.numpy.clip(x1, 0, width)\n            y1 = ops.numpy.clip(y1, 0, height)\n            x2 = ops.numpy.clip(x2, 0, width)\n            y2 = ops.numpy.clip(y2, 0, height)\n            boxes = ops.numpy.concatenate([x1, y1, x2, y2], axis=-1)","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py#L98-L134","documentation":"clip_to_image_size clips bounding boxes to the image boundaries. Only 'xyxy' and 'rel_xyxy' formats are supported (others raise NotImplementedError). In absolute 'xyxy' coordinates the function needs the pixel height and width to clip against, so passing height=None or width=None with that format raises this ValueError.","triggerScenarios":"Calling clip_to_image_size(boxes, bounding_box_format=\"xyxy\") without height/width, or with only one of them set.","commonSituations":"Pipeline refactor from relative to absolute coordinates where the image-size arguments were dropped; calling the utility on tensors whose spatial dims are unknown so the caller skipped sizes.","solutions":["Pass integer height and width matching the image the boxes refer to, e.g. clip_to_image_size(bb, height=416, width=416, bounding_box_format=\"xyxy\").","If sizes are unknown, use format='rel_xyxy' so no height/width is needed."],"exampleFix":"# before\nclipped = clip_to_image_size(boxes, bounding_box_format=\"xyxy\")\n# after\nclipped = clip_to_image_size(boxes, bounding_box_format=\"xyxy\", height=img.shape[1], width=img.shape[2])","handlingStrategy":"validation","validationCode":"if bounding_box_format == \"xyxy\":\n    assert height is not None and width is not None, \"xyxy requires height and width\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Thread image height/width through your preprocessing pipeline alongside the boxes."],"tags":["keras","bounding-boxes","clip","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}