Auto-generate labelmap for voc from task (#1214)

main
zhiltsov-max 6 years ago committed by GitHub
parent 5dc52f94a2
commit 3604f0c5ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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):

@ -155,7 +155,12 @@ class VocExtractor(SourceExtractor):
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

Loading…
Cancel
Save