Skip to content

yolo-to-voc: Convert YOLO to Pascal VOC Format

The yolo-to-voc command converts YOLO format annotations (text files) to Pascal VOC XML format. Since YOLO annotations don't include image dimensions, corresponding images must be provided to extract this information.

Usage

m3-download yolo-to-voc YOLO_DIR IMAGE_DIR NAMES_FILE OUTPUT_DIR [--verbose]

Parameters

  • YOLO_DIR: Directory containing YOLO annotation text files
  • IMAGE_DIR: Directory containing corresponding images (PNG or JPG)
  • NAMES_FILE: File containing class names, one per line
  • OUTPUT_DIR: Directory where VOC XML files will be saved
  • --verbose, -v: (Optional) Display additional information about file matching

How It Works

  1. The command matches annotation files with image files by their filename stems
  2. For each matched pair, it:
    • Reads the image dimensions using the imagesize library
    • Converts YOLO's normalized coordinates to absolute pixel coordinates
    • Creates a Pascal VOC XML using the pascal_voc_writer library
    • Saves the XML to the output directory

Notes

File Requirements

  • YOLO annotations must have the .txt file extension
  • Image files must have .png or .jpg file extensions
  • Files are matched based on filename stem (name without extension)

Missing Matches

If an annotation file has no matching image file or vice versa, a warning will be displayed and those files will be skipped.

Examples

Basic conversion:

m3-download yolo-to-voc yolo_annotations/ images/ yolo.names voc_annotations/

Verbose output to debug file matching issues:

m3-download yolo-to-voc yolo_annotations/ images/ yolo.names voc_annotations/ --verbose