Skip to content

Commit 80b95c1

Browse files
authored
AC: get meta from converter (#2949)
1 parent b5c91b2 commit 80b95c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+307
-215
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/action_recognition.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,25 @@ def configure(self):
101101
warnings.warn("image_subpath is provided. "
102102
"Make sure that data_source is {}".format(self.data_dir / self.image_subdir))
103103

104-
def convert(self, check_content=False, progress_callback=None, progress_interval=100, **kwargs):
105-
full_annotation = read_json(self.annotation_file, object_pairs_hook=OrderedDict)
106-
data_ext, data_dir = self.get_ext_and_dir()
107-
label_map = dict(enumerate(full_annotation['labels']))
104+
def get_meta(self):
108105
if self.dataset_meta:
109106
dataset_meta = read_json(self.dataset_meta)
110107
if 'label_map' in dataset_meta:
111108
label_map = dataset_meta['label_map']
112109
label_map = verify_label_map(label_map)
113-
elif 'labels' in dataset_meta:
110+
return {'label_map': label_map}
111+
if 'labels' in dataset_meta:
114112
label_map = dict(enumerate(dataset_meta['labels']))
113+
return {'label_map': label_map}
114+
full_annotation = read_json(self.annotation_file, object_pairs_hook=OrderedDict)
115+
label_map = dict(enumerate(full_annotation['labels']))
116+
return {'label_map': label_map}
117+
118+
def convert(self, check_content=False, progress_callback=None, progress_interval=100, **kwargs):
119+
full_annotation = read_json(self.annotation_file, object_pairs_hook=OrderedDict)
120+
meta = self.get_meta()
121+
label_map = meta['label_map']
122+
data_ext, data_dir = self.get_ext_and_dir()
115123
video_names, annotations = self.get_video_names_and_annotations(full_annotation['database'], self.subset)
116124
class_to_idx = {v: k for k, v in label_map.items()}
117125

@@ -143,7 +151,7 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
143151

144152
annotations.append(ClassificationAnnotation(identifier, clip['label']))
145153

146-
return ConverterReturn(annotations, {'label_map': label_map}, content_errors)
154+
return ConverterReturn(annotations, meta, content_errors)
147155

148156
def get_ext_and_dir(self):
149157
if self.two_stream_input:

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/ade20k_dataset_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
5656
if progress_callback and idx % progress_interval == 0:
5757
progress_callback(idx * 100 / num_iterations)
5858
annotations.append(SegmentationAnnotation(identifier, annotation_path.name))
59-
return ConverterReturn(annotations, self.read_meta(), content_errors)
59+
return ConverterReturn(annotations, self.get_meta(), content_errors)
6060

61-
def read_meta(self):
61+
def get_meta(self):
6262
categories_dist = DictReader(self.object_categories_file.open(), delimiter='\t')
6363
if self.num_classes:
6464
label_map = {int(category['Idx']): category['Name'] for category in categories_dist

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/amazon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def __next__(self):
162162

163163
return source, target
164164

165+
165166
class AmazonProductData(BaseFormatConverter):
166167

167168
__provider__ = 'amazon_product_data'

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/antispoofing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
limitations under the License.
1515
"""
1616

17-
from .format_converter import ConverterReturn, FileBasedAnnotationConverter
17+
from .format_converter import ConverterReturn, FileBasedAnnotationConverter, verify_label_map
1818
from ..representation import ClassificationAnnotation
1919
from ..utils import read_json, check_file_existence
2020
from ..config import PathField, NumberField
2121

22+
2223
class AntispoofingDatasetConverter(FileBasedAnnotationConverter):
2324
__provider__ = 'antispoofing'
2425
annotation_types = (ClassificationAnnotation, )
@@ -68,7 +69,7 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
6869
annotation_tuple = self.generate_annotations()
6970
annotations = []
7071
content_errors = None if not check_content else []
71-
meta = self.generate_meta()
72+
meta = self.get_meta()
7273
num_iterations = len(annotations)
7374

7475
for i, (img_name, label, bbox) in enumerate(annotation_tuple):
@@ -85,11 +86,15 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
8586

8687
return ConverterReturn(annotations, meta, content_errors)
8788

88-
def generate_meta(self):
89+
def get_meta(self):
8990
if not self.meta:
9091
return {'label_map': {'real': 0, 'spoof': 1}}
9192
dataset_meta = read_json(self.meta)
9293
label_map = dataset_meta.get('label_map')
94+
if label_map:
95+
label_map = verify_label_map(label_map)
96+
if not label_map and 'labels' in dataset_meta:
97+
label_map = dict(enumerate(dataset_meta['labels']))
9398
dataset_meta['label_map'] = label_map or {'real': 0, 'spoof': 1}
9499
return dataset_meta
95100

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/background_matting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
8383
progress_callback(idx / num_iterations * 100)
8484

8585
return ConverterReturn(
86-
annotations, {'label_map': {'background': 0, 'foreground': list(range(1, 256))}}, content_errors
86+
annotations, self.get_meta(), content_errors
8787
)
8888

89+
def get_meta(self):
90+
return {'label_map': {'background': 0, 'foreground': list(range(1, 256))}}
91+
8992

9093
class VideoBackgroundMatting(BackgroundMattingConverter):
9194
__provider__ = 'video_background_matting'
@@ -125,5 +128,5 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
125128
progress_callback(idx / num_iterations * 100)
126129

127130
return ConverterReturn(
128-
annotations, {'label_map': {'background': 0, 'foreground': list(range(1, 256))}}, content_errors
131+
annotations, self.get_meta(), content_errors
129132
)

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/brats.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
except ImportError as import_error:
3131
nib = UnsupportedPackage("nibabel", import_error.msg)
3232

33+
3334
class BratsConverter(DirectoryBasedAnnotationConverter):
3435
__provider__ = 'brats'
3536
annotation_types = (BrainTumorSegmentationAnnotation, )
@@ -125,9 +126,9 @@ def convert(self, check_content=False, **kwargs):
125126

126127
annotations.append(annotation)
127128

128-
return ConverterReturn(annotations, self._get_meta(), content_check_errors)
129+
return ConverterReturn(annotations, self.get_meta(), content_check_errors)
129130

130-
def _get_meta(self):
131+
def get_meta(self):
131132
if not self.labels_file:
132133
return None
133134
return {'label_map': dict(enumerate(read_txt(self.labels_file)))}
@@ -222,9 +223,9 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
222223
if progress_callback is not None and i % progress_interval == 0:
223224
progress_callback(i / num_iterations * 100)
224225

225-
return ConverterReturn(annotations, self._get_meta(), check_content_errors)
226+
return ConverterReturn(annotations, self.get_meta(), check_content_errors)
226227

227-
def _get_meta(self):
228+
def get_meta(self):
228229
if not self.labels_file:
229230
return None
230231
return {'label_map': dict(enumerate(read_txt(self.labels_file)))}

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/camvid.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
7676
annotations.append(SegmentationAnnotation(identifier, gt_file))
7777
if progress_callback is not None and line_id % progress_interval == 0:
7878
progress_callback(line_id * 100 / num_iterations)
79+
return ConverterReturn(annotations, self.get_meta(), content_errors)
80+
81+
def get_meta(self):
7982
meta = self.meta
8083
if self.dataset_meta:
8184
meta = read_json(self.dataset_meta)
8285
if 'label_map' in meta:
8386
meta['label_map'] = verify_label_map(meta['label_map'])
8487
if 'labels' in meta and 'label_map' not in meta:
8588
meta['label_map'] = dict(enumerate(meta['labels']))
86-
87-
return ConverterReturn(annotations, meta, content_errors)
89+
return meta
8890

8991

9092
class CamVid32DatasetConverter(BaseFormatConverter):
@@ -169,12 +171,14 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
169171
if progress_callback and idx % progress_interval == 0:
170172
progress_callback(idx * 100 / val_subset_size)
171173

174+
return ConverterReturn(annotations, self.get_meta(), content_errors)
175+
176+
def get_meta(self):
172177
meta = self.meta
173178
if self.dataset_meta:
174179
meta = read_json(self.dataset_meta)
175180
if 'label_map' in meta:
176181
meta['label_map'] = verify_label_map(meta['label_map'])
177182
if 'labels' in meta and 'label_map' not in meta:
178183
meta['label_map'] = dict(enumerate(meta['labels']))
179-
180-
return ConverterReturn(annotations, meta, content_errors)
184+
return meta

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/cifar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,12 @@ def generate_meta(self, labels_offset, annotation):
204204
meta['background_label'] = 0
205205

206206
return meta, labels, labels_id
207+
208+
def get_meta(self):
209+
annotation_dict = read_pickle(self.data_batch_file, encoding='latin1')
210+
labels_offset = 0 if not self.has_background else 1
211+
# crete metadata for dataset. Provided additional information is task specific and can includes, for example
212+
# label_map, information about background, used class color representation (for semantic segmentation task)
213+
# If your dataset does not have additional meta, you can to not provide it.
214+
meta, _, _ = self.generate_meta(labels_offset, annotation_dict)
215+
return meta

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/cityscapes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ def convert(self, check_content=False, progress_callback=None, progress_interval
123123
if progress_callback is not None and idx % progress_interval == 0:
124124
progress_callback(idx / num_iterations * 100)
125125

126-
return ConverterReturn(annotations, self.generate_meta(), content_errors)
126+
return ConverterReturn(annotations, self.get_meta(), content_errors)
127127

128-
def generate_meta(self):
128+
def get_meta(self):
129129
if self.dataset_meta_file is not None:
130130
meta = read_json(self.dataset_meta_file)
131131
if 'label_map' in meta:

tools/accuracy_checker/openvino/tools/accuracy_checker/annotation_converters/coco_facial_landmarks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def configure(self):
3939
super().configure()
4040
self.images_dir = self.get_value_from_config('images_dir') or self.annotation_file.parent
4141

42-
@classmethod
43-
def _collectImageIds(cls, data):
42+
@staticmethod
43+
def _collect_image_ids(data):
4444
result = {}
4545
for itm in data:
4646
img_name = itm["file_name"]
@@ -49,12 +49,11 @@ def _collectImageIds(cls, data):
4949

5050
return result
5151

52-
5352
def convert(self, check_content=False, progress_callback=None, progress_interval=100, **kwargs):
5453
with open(self.annotation_file, encoding='UTF-8') as f:
5554
data = json.load(f)
5655
coco_ann = data["annotations"]
57-
id2name = self._collectImageIds(data["images"])
56+
id2name = self._collect_image_ids(data["images"])
5857
num_landmarks = 98
5958
annotations = []
6059
for ann_id, ann in enumerate(coco_ann[1:]):

0 commit comments

Comments
 (0)