roboflow/supervision · error · ValueError

Missing polygon coordinate value in Pascal VOC.

Error message

Missing polygon coordinate value in Pascal VOC.

What it means

Raised by parse_polygon_points when iterating the descendants of a <polygon> element and a coordinate tag has no text content (coord.text is None). Pascal VOC polygon extensions expect alternating x/y leaf tags with integer text; an empty tag such as <x></x> makes the integer coordinate unreadable, so parsing aborts.

Source

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

    annotation = Detections(
        xyxy=xyxy_arr,
        mask=mask_arr,
        class_id=class_id,
    )

    return annotation, extended_classes


def _with_poly_mask(obj: Element) -> bool:
    return obj.find("polygon") is not None


def parse_polygon_points(polygon: Element) -> npt.NDArray[np.int_]:
    coordinates: list[int] = []
    for coord in polygon.findall(".//*"):
        if coord.text is None:
            raise ValueError("Missing polygon coordinate value in Pascal VOC.")
        coordinates.append(int(coord.text))
    return np.array(
        [(coordinates[i], coordinates[i + 1]) for i in range(0, len(coordinates), 2)],
        dtype=int,
    )


def _get_required_text(element: Element, tag: str) -> str:
    child = element.find(tag)
    if child is None or child.text is None:
        raise ValueError(f"Missing '{tag}' in Pascal VOC annotation.")
    return child.text


def save_pascal_voc_annotations(
    dataset: "DetectionDataset",
    annotations_directory_path: str,
    min_image_area_percentage: float = 0.0,

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Inspect the polygon block of the failing annotation for empty or self-closing coordinate tags.
  2. Fill in the missing integer coordinate or remove the incomplete <polygon> element.
  3. If the whole object is bad, delete the <object> and re-annotate that image.
  4. Re-export from the source annotation tool after fixing the polygon there.

Example fix

<!-- before -->
<polygon><x>10</x><y></y><x>50</x><y>60</y></polygon>
<!-- after -->
<polygon><x>10</x><y>20</y><x>50</x><y>60</y></polygon>
Defensive patterns

Strategy: validation

Validate before calling

import xml.etree.ElementTree as ET

def polygon_coords_complete(xml_path: str) -> bool:
    """Check every polygon coordinate leaf has non-empty integer text."""
    root = ET.parse(xml_path).getroot()
    for poly in root.iter('polygon'):
        for coord in poly.findall('.//*'):
            if coord.text is None or not coord.text.strip().lstrip('-').isdigit():
                return False
    return True

Try / catch

try:
    dataset = sv.DetectionDataset.from_pascal_voc(images_dir, ann_dir)
except ValueError as e:
    if 'Missing polygon coordinate' in str(e):
        raise RuntimeError(f'Incomplete polygon in {xml_path}: {e}') from e
    raise

Prevention

When it happens

Trigger: Loading a Pascal VOC dataset with force_masks=True, or where any object has a <polygon> child, and one of the coordinate sub-elements is empty (e.g. <x/>) or contains only a comment/whitespace-only structure that ElementTree reports as None text.

Common situations: Hand-edited polygons; export tools that write self-closing coordinate tags for missing values; partially written annotations from a crashed annotator; datasets converted from other formats with missing numeric fields.

Related errors


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