{"record":{"id":"ce051d08c045b62d","repo":"roboflow/supervision","slug":"missing-bndbox-in-pascal-voc-annotation","errorCode":null,"errorMessage":"Missing bndbox in Pascal VOC annotation.","messagePattern":"Missing bndbox in Pascal VOC annotation\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/dataset/formats/pascal_voc.py","lineNumber":314,"sourceCode":"            updated list of class names, extended with the class names\n            from the XML object. The Detections ``class_id`` is always an\n            integer-dtype array, including the zero-``<object>`` (background)\n            case where it is empty.\n    \"\"\"\n    xyxy: list[list[int]] = []\n    class_names: list[str] = []\n    masks: list[npt.NDArray[np.bool_]] = []\n    with_masks = force_masks or any(\n        _with_poly_mask(obj) for obj in root.findall(\"object\")\n    )\n    extended_classes = classes[:]\n    for obj in root.findall(\"object\"):\n        class_name = _get_required_text(obj, \"name\")\n        class_names.append(class_name)\n\n        bbox = obj.find(\"bndbox\")\n        if bbox is None:\n            raise ValueError(\"Missing bndbox in Pascal VOC annotation.\")\n        x1 = int(_get_required_text(bbox, \"xmin\"))\n        y1 = int(_get_required_text(bbox, \"ymin\"))\n        x2 = int(_get_required_text(bbox, \"xmax\"))\n        y2 = int(_get_required_text(bbox, \"ymax\"))\n\n        xyxy.append([x1, y1, x2, y2])\n\n        object_mask: npt.NDArray[np.bool_] = np.zeros(\n            (resolution_wh[1], resolution_wh[0]), dtype=bool\n        )\n        for polygon_element in obj.findall(\"polygon\"):\n            polygon = parse_polygon_points(polygon_element)\n            # https://github.com/roboflow/supervision/issues/144\n            polygon -= 1\n\n            mask_from_polygon = polygon_to_mask(\n                polygon=polygon,\n                resolution_wh=resolution_wh,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/dataset/formats/pascal_voc.py#L296-L332","documentation":"Raised in detections_from_xml_obj when an <object> element in a Pascal VOC annotation has no <bndbox> child. Pascal VOC requires every object to carry a bndbox with xmin/ymin/xmax/ymax, so supervision refuses to guess coordinates and fails loudly. This protects downstream code that assumes every xyxy row is valid.","triggerScenarios":"Loading a Pascal VOC dataset (DetectionDataset.from_pascal_voc) where at least one <object> element lacks a <bndbox> subtree — e.g. hand-edited XML, segmentation-only exports, or converter tools that omit bndbox.","commonSituations":"Annotations exported by nonstandard tools (some segmentation annotators write only <polygon>); manual XML edits that deleted the bndbox; truncated XML written by a crashing exporter; datasets mixing VOC-like dialects.","solutions":["Open the annotation file for the failing image and find the <object> without <bndbox>.","Add a valid <bndbox><xmin>..<ymax></bndbox> block — if the object only has polygon points, compute the bounding box from the polygon min/max.","If the object is spurious, remove the whole <object> element.","If produced by a converter, fix or configure the converter to always emit bndbox, then re-export."],"exampleFix":"<!-- before -->\n<object>\n  <name>dog</name>\n  <polygon><x>10</x><y>10</y>...</polygon>\n</object>\n<!-- after: bndbox derived from polygon extremes -->\n<object>\n  <name>dog</name>\n  <bndbox><xmin>10</xmin><ymin>10</ymin><xmax>180</xmax><ymax>220</ymax></bndbox>\n  <polygon><x>10</x><y>10</y>...</polygon>\n</object>","handlingStrategy":"validation","validationCode":"import xml.etree.ElementTree as ET\nfrom pathlib import Path\n\ndef objects_missing_bndbox(xml_path: str) -> int:\n    \"\"\"Count <object> elements lacking <bndbox> in a VOC file.\"\"\"\n    root = ET.parse(xml_path).getroot()\n    return sum(1 for obj in root.findall('object')\n               if obj.find('bndbox') is None)","typeGuard":null,"tryCatchPattern":"try:\n    dataset = sv.DetectionDataset.from_pascal_voc(images_dir, ann_dir)\nexcept ValueError as e:\n    if 'Missing bndbox' in str(e):\n        raise RuntimeError(f'Corrupt VOC annotation: {e}. Repair or remove the file.') from e\n    raise","preventionTips":["Prefer annotation tools and converters that always emit bndbox for VOC.","Add a schema lint step to dataset CI (every object must have bndbox).","If source data is polygon-only, compute bndbox from polygon extents during conversion."],"tags":["pascal-voc","dataset","xml","annotation-format"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}