Skip to content

Commit 60e560a

Browse files
authored
AC: support label map from datumaro (#2904)
1 parent ac8c2fe commit 60e560a

File tree

1 file changed

+22
-2
lines changed
  • tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters

1 file changed

+22
-2
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/pascal_voc.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ..config import PathField, BoolField
1818
from ..representation import DetectionAnnotation, SegmentationAnnotation
1919
from ..representation.segmentation_representation import GTMaskLoader
20-
from ..utils import get_path, read_txt, read_xml, check_file_existence, read_json
20+
from ..utils import get_path, read_txt, read_xml, check_file_existence, read_json, string_to_tuple
2121
from .format_converter import BaseFormatConverter, ConverterReturn, verify_label_map
2222

2323
_SYG_CLASSES_DETECTION = (
@@ -91,6 +91,7 @@ def syg_prepare_detection_labels(dataset_meta, has_background=True):
9191

9292
return reversed_label_map
9393

94+
9495
class PascalVOCSegmentationConverter(BaseFormatConverter):
9596
__provider__ = 'voc_segmentation'
9697
annotation_types = (SegmentationAnnotation, )
@@ -111,7 +112,8 @@ def parameters(cls):
111112
),
112113
'dataset_meta_file': PathField(
113114
description='path to json file with dataset meta (e.g. label_map, color_encoding)', optional=True
114-
)
115+
),
116+
'labelmap_file': PathField(description='labelmap.txt in Datumaro format', optional=True)
115117
})
116118

117119
return configuration_parameters
@@ -121,6 +123,9 @@ def configure(self):
121123
self.image_dir = self.get_value_from_config('images_dir')
122124
dataset_meta_file = self.get_value_from_config('dataset_meta_file')
123125
self.dataset_meta = {} if not dataset_meta_file else read_json(dataset_meta_file)
126+
labelmap_file = self.get_value_from_config('labelmap_file')
127+
if labelmap_file is not None:
128+
self.dataset_meta.update(self.read_labelmap(labelmap_file))
124129
if not self.image_dir:
125130
self.image_dir = get_path(self.image_set_file.parents[-2] / 'JPEGImages', is_directory=True)
126131

@@ -156,6 +161,21 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
156161

157162
return ConverterReturn(annotations, meta, content_check_errors)
158163

164+
@staticmethod
165+
def read_labelmap(input_file):
166+
label_map = {}
167+
segmentation_colors = []
168+
idx = 0
169+
for line in read_txt(input_file):
170+
if line.startswith('#'):
171+
continue
172+
data = line.split(':')
173+
label, color = data[:2]
174+
label_map[idx] = label
175+
segmentation_colors.append(string_to_tuple(color))
176+
idx += 1
177+
return {'label_map': label_map, 'segmentation_colors': segmentation_colors}
178+
159179

160180
class PascalVOCDetectionConverter(BaseFormatConverter):
161181
__provider__ = 'voc_detection'

0 commit comments

Comments
 (0)