DEV Community

Taskmonk Team
Taskmonk Team

Posted on

COCO vs YOLO vs Pascal VOC: Choosing an Annotation Export Format

Labeled data is only useful if your training code can read it. Most computer vision projects end up using one of three formats: COCO JSON, YOLO TXT or Pascal VOC XML. Here is how they differ and when to use each.

COCO (JSON)

One JSON file per dataset split, with images, annotations and categories arrays.

{
  "images": [{"id": 1, "file_name": "shelf_001.jpg", "width": 1920, "height": 1080}],
  "annotations": [{"id": 10, "image_id": 1, "category_id": 3,
                   "bbox": [412, 220, 180, 96], "area": 17280,
                   "segmentation": [[412,220,592,220,592,316,412,316]], "iscrowd": 0}],
  "categories": [{"id": 3, "name": "bottle"}]
}
Enter fullscreen mode Exit fullscreen mode
  • Boxes are [x, y, width, height] in pixels, from the top-left corner.
  • Supports polygons, RLE masks and keypoints.
  • Best for: instance segmentation, keypoints, and any project that uses Detectron2 or MMDetection.

YOLO (TXT)

One .txt file per image, one line per object:

3 0.2615 0.2481 0.0938 0.0889
Enter fullscreen mode Exit fullscreen mode
  • Class index, then box centre x, centre y, width and height, all normalised to 0–1.
  • Very compact and easy to generate.
  • Best for: Ultralytics YOLO training and fast detection pipelines.

Pascal VOC (XML)

One .xml file per image, with <object> blocks and xmin, ymin, xmax, ymax corners in pixels.

  • Human-readable and widely supported by older tools.
  • Best for: legacy pipelines and TensorFlow Object Detection API setups.

Converting between them

The most common bug is mixing coordinate conventions. A quick YOLO-to-COCO conversion:

def yolo_to_coco(cx, cy, w, h, img_w, img_h):
    bw, bh = w * img_w, h * img_h
    x = cx * img_w - bw / 2
    y = cy * img_h - bh / 2
    return [round(x, 2), round(y, 2), round(bw, 2), round(bh, 2)]
Enter fullscreen mode Exit fullscreen mode

Always draw a sample of converted boxes back onto images before training. Off-by-half-a-box errors are easy to miss in numbers and obvious in pictures.

Tip: export more than you need

Keep a master export in COCO (it holds the most information) and generate YOLO or VOC from it. Converting the other way loses masks and keypoints.

Annotation platforms such as Taskmonk export to all three formats, so you can switch frameworks without relabeling. For 3D data, see LiDAR annotation formats like KITTI and nuScenes.

Top comments (0)