Skip to content

Commit

Permalink
fix ids (cvat-ai#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Zhiltsov authored Sep 10, 2020
1 parent 2756d7f commit fd67751
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datumaro/plugins/coco_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def save_annotations(self, item):
def write(self, path):
next_id = self._min_ann_id
for ann in self.annotations:
if ann['id'] is None:
if not ann['id']:
ann['id'] = next_id
next_id += 1

Expand Down
18 changes: 18 additions & 0 deletions tests/test_coco_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,21 @@ def test_annotation_attributes(self):
with TestDir() as test_dir:
self._test_save_and_load(expected_dataset,
CocoConverter.convert, test_dir)

def test_auto_annotation_ids(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id=2, image=np.ones((4, 2, 3)), annotations=[
Polygon([0, 0, 4, 0, 4, 4], label=0),
])
], categories=[str(i) for i in range(10)])

target_dataset = Dataset.from_iterable([
DatasetItem(id=2, image=np.ones((4, 2, 3)), annotations=[
Polygon([0, 0, 4, 0, 4, 4], label=0, id=1, group=1,
attributes={'is_crowd': False}),
], attributes={'id': 1})
], categories=[str(i) for i in range(10)])

with TestDir() as test_dir:
self._test_save_and_load(source_dataset,
CocoConverter.convert, test_dir, target_dataset=target_dataset)

0 comments on commit fd67751

Please sign in to comment.