The Issue:
I export some annotations using:
sv.DetectionDataset(
classes=CLASSES,
images=images,
annotations=annotations
).as_coco(
annotations_path=ANNOTATIONS_PATH,
min_image_area_percentage=0,
max_image_area_percentage=1.,
approximation_percentage=0
)
The resulting .json is created successfully.
Then, loading the annotations using pycocotools and plotting annotations of an image:
from pycocotools.coco import COCO
coco=COCO(ANNOTATIONS_PATH)
imgId = 42 # an arbitrary image id
file_name = coco.loadImgs(imgId)[0]["file_name"]
img = plt.imread(file_name)
plt.imshow(img)
plt.axis("off")
annIds = coco.getAnnIds(imgIds=imgId, iscrowd=None)
anns = coco.loadAnns(annIds)
coco.showAnns(anns, draw_bbox=True)
which plots wrong annotations for the given imgId: the annotations (box & mask) is seen bottom-right and it seems that there is a mismatch between the image and its annotations.

Actually, for any imgId, we have the same issue: the image is shown correctly but the annotations are not. Interestingly, the annotations (annIds) are always the same for different imgId's. In my case, there is only 1 box & mask per image and for various values of imgId, the annIds are always equal to 1.
The Cause:
The annIds are not unique among all the annotations (the "id" in "annotations" in COCO format).
I presume they have to be unique among all annotation id's (see the following issue).
However, the current implementation resets the annotation id to 1 for each image:
|
image_id, annotation_id = 1, 1 |
The (possible) Fix:
Simply changing label_id to annotation_id in the following line will assign a unique id for each annotation:
|
coco_annotation, label_id = detections_to_coco_annotations( |
I would be glad to open a PR.
The Issue:
I export some annotations using:
The resulting
.jsonis created successfully.Then, loading the annotations using
pycocotoolsand plotting annotations of an image:which plots wrong annotations for the given

imgId: the annotations (box & mask) is seen bottom-right and it seems that there is a mismatch between the image and its annotations.Actually, for any
imgId, we have the same issue: the image is shown correctly but the annotations are not. Interestingly, the annotations (annIds) are always the same for differentimgId's. In my case, there is only 1 box & mask per image and for various values ofimgId, theannIdsare always equal to1.The Cause:
The
annIdsare not unique among all the annotations (the "id" in "annotations" in COCO format).I presume they have to be unique among all annotation id's (see the following issue).
However, the current implementation resets the annotation id to 1 for each image:
supervision/supervision/dataset/formats/coco.py
Line 202 in 4f79d29
The (possible) Fix:
Simply changing
label_idtoannotation_idin the following line will assign a unique id for each annotation:supervision/supervision/dataset/formats/coco.py
Line 218 in 4f79d29
I would be glad to open a PR.