roboflow/supervision · error · ValueError
Missing '{tag}' in Pascal VOC annotation.
Error message
Missing '{tag}' in Pascal VOC annotation. What it means
Raised by _get_required_text in the Pascal VOC loader when a required child element (e.g. name within object, or width/height within size) is missing from the XML or has empty text. It is the generic required-field accessor used while parsing VOC XML annotation objects.
Source
Thrown at src/supervision/dataset/formats/pascal_voc.py:398
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,
max_image_area_percentage: float = 1.0,
approximation_percentage: float = 0.75,
show_progress: bool = False,
) -> None:
"""Write Pascal VOC XML annotation files for every image in *dataset*.
Args:
dataset: Dataset whose annotations are saved.
annotations_directory_path: Destination directory for ``.xml`` files;
created automatically if it does not exist.
min_image_area_percentage: Minimum detection area as a fraction of theView on GitHub (pinned to 7f254d9784)
Solutions
- Open the reported XML file and add the missing element with its text value (e.g. <name>dog</name> inside <object>).
- If generating VOC XML yourself, use supervision's object_to_pascal_voc / save_pascal_voc_annotations which always emit required fields.
- Validate files with a quick lxml/ElementTree pass checking for empty required tags before bulk loading.
Example fix
// before <object><bndbox><xmin>1</xmin>...</bndbox></object> // after <object><name>dog</name><bndbox><xmin>1</xmin>...</bndbox></object>
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
from xml.etree import ElementTree as ET
def validate_voc_xml(file_path: str) -> list[str]:
"""Return list of missing required elements in a VOC XML file."""
root = ET.parse(file_path).getroot()
problems = []
for tag in ("size/width", "size/height", "size/depth"):
el = root.find(tag)
if el is None or not (el.text or "").strip():
problems.append(tag)
for obj in root.findall("object"):
name = obj.find("name")
if name is None or not (name.text or "").strip():
problems.append(f"object[{obj.findtext('name', default='?')}]/name")
return problems Type guard
def is_complete_voc_object(obj: ET.Element) -> bool:
"""True when an <object> has non-empty name and bndbox coordinates."""
name = obj.find("name")
bnd = obj.find("bndbox")
return (
name is not None and bool((name.text or "").strip())
and bnd is not None
and all((bnd.findtext(t) or "").strip() for t in ("xmin", "ymin", "xmax", "ymax"))
) Try / catch
try:
sv.DetectionDataset.from_pascal_voc(images_directory_path=d, annotations_directory_path=a)
except ValueError as exc:
if "Missing" in str(exc) and "Pascal VOC" in str(exc):
problems = validate_voc_xml(str(exc_file)) # identify and repair the file
raise ValueError(f"Incomplete VOC XML: {problems}") from exc
raise Prevention
- Generate VOC XML with supervision's object_to_pascal_voc rather than by hand.
- Require <name> text on every <object> in your converter output.
- Spot-check third-party VOC sets with an ElementTree scan before bulk loading.
When it happens
Trigger: Loading a Pascal VOC XML file via load_pascal_voc_annotations / detections_from_xml_obj where an <object> lacks <name>, or <size> lacks <width>/<height>/<depth>, or any other element fetched through _get_required_text has no text content.
Common situations: Truncated or hand-edited XML; converters that omit <name> for objects; XML files from non-standard VOC dialects; elements written as <name/> self-closing (text is None).
Related errors
- Malformed CreateML annotation entry (missing or non-string '
- CreateML annotation entry is missing the required 'image' ke
- Malformed CreateML annotation entry {annotation}: {exc}
- Failed to parse XML root from {annotation_path}
- Missing bndbox in Pascal VOC annotation.
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/592fc06c761d5583.
Report an issue: GitHub.