Skip to content

Commit

Permalink
Auto-generate labelmap for voc from task (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored Feb 28, 2020
1 parent 5dc52f9 commit 3604f0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cvat/apps/annotation/pascal_voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def load(file_object, annotations):
with TemporaryDirectory() as tmp_dir:
Archive(archive_file).extractall(tmp_dir)

# put label map from the task if not present
labelmap_file = osp.join(tmp_dir, 'labelmap.txt')
if not osp.isfile(labelmap_file):
labels = (label['name'] + ':::'
for _, label in annotations.meta['task']['labels'])
with open(labelmap_file, 'w') as f:
f.write('\n'.join(labels))

# support flat archive layout
anno_dir = osp.join(tmp_dir, 'Annotations')
if not osp.isdir(anno_dir):
Expand Down
7 changes: 6 additions & 1 deletion datumaro/datumaro/plugins/voc_format/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ def _get(self, item_id, subset_name):

def _get_label_id(self, label):
label_id, _ = self._categories[AnnotationType.label].find(label)
assert label_id is not None
if label_id is None:
log.debug("Unknown label '%s'. Loaded labels: %s",
label,
', '.join("'%s'" % s.name
for s in self._categories[AnnotationType.label].items))
raise Exception("Unknown label '%s'" % label)
return label_id

@staticmethod
Expand Down

0 comments on commit 3604f0c

Please sign in to comment.