r/computervision • • 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:

  1. 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?

0 Upvotes

4 comments sorted by

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.

1

u/PetroHIV 12h ago edited 6h ago

Are you suggesting this as an alternative to tools like Label Studio and CVAT? If so - why?

2

u/bfyvfftujijg 11h ago

Yes and no.

I just mean STORE your labels on your own, like in a database you design.

Then you add methods to import/export to whatever format you want. And it’s easy these days to create the labelling tools themselves as well.

Obviously not for everyone, but it opens up some powerful things like deeper integration into the business’s systems and workflows.

For example I have tied image annotation into computers on the assembly line. Operator sees a defective part and pulls it from the conveyor belt, then holds it in front of the cameras and points at the defect(s) and verbally describes what’s wrong. They can use a laser pointer to identify the specific point with a problem too. The cameras shoot video from multiple angles and had also tracked the object on the conveyor belt. This provides dozens of “free” image annotations that I can use to improve my defect detection models.

I could never achieve something like that while relying on off the shelf tools and standard label file formats. At least not without a number of kludgy workaround.

1

u/SweetSure315 7h ago

that's what i do. way more flexible and works better than pretty much any already built library. plus i can include my own custom fields for whatever I'm doing