COCO -> YOLO/VOC export keeps crowd regions (is_crowd) as ordinary objects
Describe the bug
- Crowd regions become objects. COCO annotations with
iscrowd: 1are ignore regions in COCO evaluation. When a COCO dataset is exported toyolo, they are written as ordinary boxes, so a model trained on the export learns crowd blobs as single objects. Invoc_detectionthe flag survives only as a custom<attributes><attribute><name>is_crowd</name>block, which VOC readers do not know, so after a re-import elsewhere the crowd region is again an ordinary object. Nothing is logged. - Coordinate convention (question).
voc_detectionwritesx, y, x+w, y+has floats (e.g.10.5). The VOC devkit uses 1-based integer pixel indices, so readers that follow the devkit shift such boxes by one pixel, and readers that cast to int lose the fraction. Is the 0-based float output intended? If yes, could it be documented?
Steps to Reproduce
Run this script (one 100x100 image, one ordinary box and one crowd region):
import json, tempfile
from pathlib import Path
import numpy as np, cv2
import datumaro as dm
tmp = Path(tempfile.mkdtemp())
(tmp / "src" / "annotations").mkdir(parents=True)
(tmp / "src" / "images" / "val").mkdir(parents=True)
cv2.imwrite(str(tmp / "src" / "images" / "val" / "a.jpg"), np.zeros((100, 100, 3), np.uint8))
coco = {
"images": [{"id": 1, "file_name": "a.jpg", "width": 100, "height": 100}],
"categories": [{"id": 1, "name": "thing"}],
"annotations": [
{"id": 1, "image_id": 1, "category_id": 1, "iscrowd": 0, "bbox": [10.5, 20.25, 30, 40], "area": 1200.0,
"segmentation": [[10.5, 20.25, 40.5, 20.25, 40.5, 60.25, 10.5, 60.25]]},
{"id": 2, "image_id": 1, "category_id": 1, "iscrowd": 1, "bbox": [50, 50, 40, 40], "area": 1600.0,
"segmentation": {"size": [100, 100], "counts": [5050] + [40, 60] * 39 + [40, 1010]}},
],
}
(tmp / "src" / "annotations" / "instances_val.json").write_text(json.dumps(coco))
ds = dm.Dataset.import_from(str(tmp / "src"), "coco_instances")
ds.export(str(tmp / "voc"), "voc_detection", save_media=False)
print(next((tmp / "voc").rglob("a.xml")).read_text())
ds.export(str(tmp / "yolo"), "yolo", save_media=False)
print(next((tmp / "yolo").rglob("a.txt")).read_text())
Current output. YOLO file (two objects; the first line is the crowd region):
0 0.700000 0.700000 0.400000 0.400000
0 0.255000 0.402500 0.300000 0.400000
VOC file (excerpt):
<difficult>0</difficult>
<bndbox><xmin>50.0</xmin><ymin>50.0</ymin><xmax>90.0</xmax><ymax>90.0</ymax></bndbox>
<attributes><attribute><name>is_crowd</name><value>True</value></attribute></attributes>
...
<bndbox><xmin>10.5</xmin><ymin>20.25</ymin><xmax>40.5</xmax><ymax>60.25</ymax></bndbox>
Expected behaviour
- YOLO: crowd regions skipped (YOLO has no ignore flag), or an option for it, with a warning in both cases.
- VOC: crowd regions skipped, or mapped to a field VOC tools understand (e.g.
difficult=1, which VOC evaluation ignores), with a warning. - VOC coordinates: either the devkit convention or a documented note that the output is 0-based and continuous.
Environment:
- OS: Linux
- Datumaro version: 1.13.11 (latest)
- Python version: 3.13
- Also: numpy 2.4.6, opencv-python 4.14.0
Found while auditing COCO converters for a study of annotation-format conversion (preprint to follow).
Hi @t7spotter , thanks for reporting the issue. There is a PR to fix the iscrowd problem, kindly contributed by @choksi2212. The PR already looks good and mergeable to me, but feel free to take a look if you want.
Regarding the second part:
The VOC devkit uses 1-based integer pixel indices
I wasn't aware about this convention, but I think you are right, I found this oddity mentioned in section 4.3 of the Pascal VOC DevKit docs:
The top-left pixel in the image has coordinates (1, 1).
For sure we can document this inconsistency in our docs, thanks for spotting it. I'm also going check if we can add a parameter to control the behavior, without breaking compatibility.
Opened a follow-up PR for the second issue: #2222