roboflow/supervision · error · ValueError

Missing bndbox in Pascal VOC annotation.

Error message

Missing bndbox in Pascal VOC annotation.

What it means

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.

Solutions

  1. Open the annotation file for the failing image and find the <object> without <bndbox>.
  2. Add a valid <bndbox><xmin>..<ymax></bndbox> block — if the object only has polygon points, compute the bounding box from the polygon min/max.
  3. If the object is spurious, remove the whole <object> element.
  4. If produced by a converter, fix or configure the converter to always emit bndbox, then re-export.

Example fix

<!-- before -->
<object>
  <name>dog</name>
  <polygon><x>10</x><y>10</y>...</polygon>
</object>
<!-- after: bndbox derived from polygon extremes -->
<object>
  <name>dog</name>
  <bndbox><xmin>10</xmin><ymin>10</ymin><xmax>180</xmax><ymax>220</ymax></bndbox>
  <polygon><x>10</x><y>10</y>...</polygon>
</object>
Defensive patterns

Strategy: validation

Validate before calling

import xml.etree.ElementTree as ET
from pathlib import Path

def objects_missing_bndbox(xml_path: str) -> int:
    """Count <object> elements lacking <bndbox> in a VOC file."""
    root = ET.parse(xml_path).getroot()
    return sum(1 for obj in root.findall('object')
               if obj.find('bndbox') is None)

Try / catch

try:
    dataset = sv.DetectionDataset.from_pascal_voc(images_dir, ann_dir)
except ValueError as e:
    if 'Missing bndbox' in str(e):
        raise RuntimeError(f'Corrupt VOC annotation: {e}. Repair or remove the file.') from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/ce051d08c045b62d. Report an issue: GitHub.

Appendix: source

Thrown at src/supervision/dataset/formats/pascal_voc.py:314

            updated list of class names, extended with the class names
            from the XML object. The Detections ``class_id`` is always an
            integer-dtype array, including the zero-``<object>`` (background)
            case where it is empty.
    """
    xyxy: list[list[int]] = []
    class_names: list[str] = []
    masks: list[npt.NDArray[np.bool_]] = []
    with_masks = force_masks or any(
        _with_poly_mask(obj) for obj in root.findall("object")
    )
    extended_classes = classes[:]
    for obj in root.findall("object"):
        class_name = _get_required_text(obj, "name")
        class_names.append(class_name)

        bbox = obj.find("bndbox")
        if bbox is None:
            raise ValueError("Missing bndbox in Pascal VOC annotation.")
        x1 = int(_get_required_text(bbox, "xmin"))
        y1 = int(_get_required_text(bbox, "ymin"))
        x2 = int(_get_required_text(bbox, "xmax"))
        y2 = int(_get_required_text(bbox, "ymax"))

        xyxy.append([x1, y1, x2, y2])

        object_mask: npt.NDArray[np.bool_] = np.zeros(
            (resolution_wh[1], resolution_wh[0]), dtype=bool
        )
        for polygon_element in obj.findall("polygon"):
            polygon = parse_polygon_points(polygon_element)
            # https://github.com/roboflow/supervision/issues/144
            polygon -= 1

            mask_from_polygon = polygon_to_mask(
                polygon=polygon,
                resolution_wh=resolution_wh,

View on GitHub (pinned to 7f254d9784)