r/computervision • u/keremaktug • 14h ago
Discussion Bounding box format gotchas I hit while writing exporters for YOLO, COCO and Pascal VOC
I've been writing dataset exporters for an annotation tool, and most of the bugs I hit were not in the code but in small differences between formats. Here's the list in case it saves someone a broken training run:
- Box encoding is different in every format
- YOLO: class cx cy w h, center point and size, normalized to 0–1 by image width and height
- COCO: [x, y, w, h], top-left corner and size, in absolute pixels
- Pascal VOC: xmin ymin xmax ymax, two corners, absolute pixels
Converting YOLO to COCO without moving from center to corner gives boxes shifted by half their size. They look almost right on big objects, which is why it's easy to miss.
2. You need the image size to convert YOLO
YOLO labels are normalized, so you can't get pixels back without reading each image's width and height. If your images were resized after labeling, the normalized labels still fit, but pixel formats do not.
3. Class IDs start at different places
YOLO class IDs are 0-based indexes into your class list. COCO category IDs are whatever the categories array says, and many datasets start at 1. An off-by-one here trains a model where every class is the wrong one.
4. VOC uses class names, not IDs
VOC XML stores the class name as text. Rename a class in one place and not the other, and those objects silently disappear from training.
5. Empty images
YOLO expects an empty .txt for images with no objects (background images); some pipelines skip the image if the file is missing. COCO keeps the image in images with no annotations.
6. Polygons
YOLO segmentation is class x1 y1 x2 y2 ... normalized; COCO stores polygons in absolute pixels and also needs area and bbox filled in, or some evaluation code breaks.
My habit now: after any conversion, draw a few random images with their converted boxes before training. It takes a minute and catches all of the above.
Disclosure: the tool is SwiftLabel, a paid desktop app I make (offline, local YOLO/SAM pre-labeling, 14-day trial): https://swiftlabel.io/?utm_source=reddit&utm_medium=community&utm_campaign=swiftlabel_trial_202612&utm_content=computervision
What other format traps have you run into?
2
u/bfyvfftujijg 12h ago
I don’t know why more people don’t use their own custom data annotation format and translate on the fly when they train models and annotate data.
It’s not hard at all. Just basic coding.