Unverified Commit 79c8dd55 authored by Haian Huang(深度眸)'s avatar Haian Huang(深度眸) Committed by GitHub
Browse files

[Feature]: Add check for ann_ids not unique (#4789)

* Add check for ann_ids not unique

* Update

* Rename variable and add comments
parent 5dd08427
......@@ -59,10 +59,15 @@ class CocoDataset(CustomDataset):
self.cat2label = {cat_id: i for i, cat_id in enumerate(self.cat_ids)}
self.img_ids = self.coco.get_img_ids()
data_infos = []
total_ann_ids = []
for i in self.img_ids:
info = self.coco.load_imgs([i])[0]
info['filename'] = info['file_name']
data_infos.append(info)
ann_ids = self.coco.get_ann_ids(img_ids=[i])
total_ann_ids.extend(ann_ids)
assert len(set(total_ann_ids)) == len(
total_ann_ids), f"Annotation ids in '{ann_file}' are not unique!"
return data_infos
def get_ann_info(self, idx):
......
import os.path as osp
import tempfile
import mmcv
import pytest
from mmdet.datasets import CocoDataset
def _create_ids_error_coco_json(json_name):
image = {
'id': 0,
'width': 640,
'height': 640,
'file_name': 'fake_name.jpg',
}
annotation_1 = {
'id': 1,
'image_id': 0,
'category_id': 0,
'area': 400,
'bbox': [50, 60, 20, 20],
'iscrowd': 0,
}
annotation_2 = {
'id': 1,
'image_id': 0,
'category_id': 0,
'area': 900,
'bbox': [100, 120, 30, 30],
'iscrowd': 0,
}
categories = [{
'id': 0,
'name': 'car',
'supercategory': 'car',
}]
fake_json = {
'images': [image],
'annotations': [annotation_1, annotation_2],
'categories': categories
}
mmcv.dump(fake_json, json_name)
def test_coco_annotation_ids_unique():
tmp_dir = tempfile.TemporaryDirectory()
fake_json_file = osp.join(tmp_dir.name, 'fake_data.json')
_create_ids_error_coco_json(fake_json_file)
# test annotation ids not unique error
with pytest.raises(AssertionError):
CocoDataset(ann_file=fake_json_file, classes=('car', ), pipeline=[])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment