Skip to content

Commit 3604f0c

Browse files
authored
Auto-generate labelmap for voc from task (#1214)
1 parent 5dc52f9 commit 3604f0c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cvat/apps/annotation/pascal_voc.py

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def load(file_object, annotations):
3636
with TemporaryDirectory() as tmp_dir:
3737
Archive(archive_file).extractall(tmp_dir)
3838

39+
# put label map from the task if not present
40+
labelmap_file = osp.join(tmp_dir, 'labelmap.txt')
41+
if not osp.isfile(labelmap_file):
42+
labels = (label['name'] + ':::'
43+
for _, label in annotations.meta['task']['labels'])
44+
with open(labelmap_file, 'w') as f:
45+
f.write('\n'.join(labels))
46+
3947
# support flat archive layout
4048
anno_dir = osp.join(tmp_dir, 'Annotations')
4149
if not osp.isdir(anno_dir):

datumaro/datumaro/plugins/voc_format/extractor.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ def _get(self, item_id, subset_name):
155155

156156
def _get_label_id(self, label):
157157
label_id, _ = self._categories[AnnotationType.label].find(label)
158-
assert label_id is not None
158+
if label_id is None:
159+
log.debug("Unknown label '%s'. Loaded labels: %s",
160+
label,
161+
', '.join("'%s'" % s.name
162+
for s in self._categories[AnnotationType.label].items))
163+
raise Exception("Unknown label '%s'" % label)
159164
return label_id
160165

161166
@staticmethod

0 commit comments

Comments
 (0)