Skip to content

Commit 04589d0

Browse files
authored
AC: add support weld porosity detection model as part of common pipeline (openvinotoolkit#1217)
* AC:add support weld porosity detection model as part of common pipeline * fix spaces * prevent problems with async execution * extend tests
1 parent 548cf15 commit 04589d0

File tree

6 files changed

+84
-7
lines changed

6 files changed

+84
-7
lines changed

tools/accuracy_checker/accuracy_checker/data_readers/data_reader.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class BaseReader(ClassProvider):
9999
__provider_type__ = 'reader'
100100

101101
def __init__(self, data_source, config=None, **kwargs):
102-
self.config = config
102+
self.config = config or {}
103103
self.data_source = data_source
104104
self.read_dispatcher = singledispatch(self.read)
105105
self.read_dispatcher.register(list, self._read_list)
@@ -127,6 +127,7 @@ def __call__(self, context=None, identifier=None, **kwargs):
127127

128128
def configure(self):
129129
self.data_source = get_path(self.data_source, is_directory=True)
130+
self.multi_infer = self.config.get('multi_infer', False)
130131

131132
def validate_config(self):
132133
pass
@@ -146,7 +147,10 @@ def _read_frames_multi_input(self, data_id):
146147
return self.read_dispatcher(data_id.frames)
147148

148149
def read_item(self, data_id):
149-
return DataRepresentation(self.read_dispatcher(data_id), identifier=data_id)
150+
data_rep = DataRepresentation(self.read_dispatcher(data_id), identifier=data_id)
151+
if self.multi_infer:
152+
data_rep.metadata['multi_infer'] = True
153+
return data_rep
150154

151155
@property
152156
def name(self):
@@ -181,6 +185,7 @@ def configure(self):
181185
reading_scheme[pattern] = reader
182186

183187
self.reading_scheme = reading_scheme
188+
self.multi_infer = self.config.get('multi_infer', False)
184189

185190
def read(self, data_id):
186191
for pattern, reader in self.reading_scheme.items():
@@ -207,14 +212,15 @@ class OpenCVImageReader(BaseReader):
207212

208213
def validate_config(self):
209214
if self.config:
210-
config_validator = OpenCVImageReaderConfig('opencv_imread_config')
215+
config_validator = OpenCVImageReaderConfig(
216+
'opencv_imread_config', on_extra_argument=ConfigValidator.IGNORE_ON_EXTRA_ARGUMENT
217+
)
211218
config_validator.validate(self.config)
212219

213220
def configure(self):
214221
super().configure()
215222
self.flag = OPENCV_IMREAD_FLAGS[self.config.get('reading_flag', 'color') if self.config else 'color']
216223

217-
218224
def read(self, data_id):
219225
return cv2.imread(str(get_path(self.data_source / data_id)), self.flag)
220226

@@ -281,6 +287,7 @@ def _read_sequence(self, data_id):
281287
def configure(self):
282288
self.data_source = get_path(self.data_source)
283289
self.videocap = cv2.VideoCapture(str(self.data_source))
290+
self.multi_infer = self.config.get('multi_infer', False)
284291

285292
def reset(self):
286293
self.current = -1
@@ -301,6 +308,7 @@ def validate_config(self):
301308

302309
def configure(self):
303310
self.key = self.config.get('key')
311+
self.multi_infer = self.config.get('multi_infer', False)
304312

305313
def read(self, data_id):
306314
data = read_json(str(self.data_source / data_id))
@@ -343,6 +351,7 @@ def configure(self):
343351
if nib is None:
344352
raise ImportError('nifty backend for image reading requires nibabel. Please install it before usage.')
345353
self.channels_first = self.config.get('channels_first', False) if self.config else False
354+
self.multi_infer = self.config.get('multi_infer', False)
346355

347356
def read(self, data_id):
348357
nib_image = nib.load(str(get_path(self.data_source / data_id)))
@@ -353,10 +362,12 @@ def read(self, data_id):
353362

354363
return image
355364

365+
356366
class NumpyReaderConfig(ConfigValidator):
357367
type = StringField(optional=True)
358368
keys = StringField(optional=True, default="")
359369

370+
360371
class NumPyReader(BaseReader):
361372
__provider__ = 'numpy_reader'
362373

@@ -366,8 +377,10 @@ def validate_config(self):
366377
config_validator.validate(self.config)
367378

368379
def configure(self):
380+
self.multi_infer = self.config.get('multi_infer', False)
369381
self.keys = self.config.get('keys', "") if self.config else ""
370382
self.keys = [t.strip() for t in self.keys.split(',')] if len(self.keys) > 0 else []
383+
self.multi_infer = self.config.get('multi_infer', False)
371384

372385
def read(self, data_id):
373386
data = np.load(str(self.data_source / data_id))
@@ -384,6 +397,7 @@ def read(self, data_id):
384397
key = next(iter(data.keys()))
385398
return data[key]
386399

400+
387401
class TensorflowImageReader(BaseReader):
388402
__provider__ = 'tf_imread'
389403

@@ -422,6 +436,7 @@ def configure(self):
422436
self.single = len(self.feature_list) == 1
423437
self.counter = 0
424438
self.subset = range(len(self.data_source))
439+
self.multi_infer = self.config.get('multi_infer', False)
425440

426441
def read(self, data_id):
427442
relevant_annotation = self.data_source[self.subset[self.counter]]

tools/accuracy_checker/accuracy_checker/dataset.py

+5
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def create_subset(annotation, subsample_size, subsample_seed, shuffle=True):
273273
raise ConfigError('subsample_size should be > 0')
274274
return make_subset(annotation, subsample_size, subsample_seed, shuffle)
275275

276+
276277
class DatasetWrapper:
277278
def __init__(self, data_reader, annotation_reader=None, tag='', dataset_config=None):
278279
self.tag = tag
@@ -353,3 +354,7 @@ def full_size(self):
353354
@property
354355
def size(self):
355356
return self.__len__()
357+
358+
@property
359+
def multi_infer(self):
360+
return getattr(self.data_reader, 'multi_infer', False)

tools/accuracy_checker/accuracy_checker/evaluators/model_evaluator.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ def prepare_dataset():
129129

130130
prepare_dataset()
131131

132-
if self.launcher.allow_reshape_input or self.preprocessor.has_multi_infer_transformations:
132+
if (
133+
self.launcher.allow_reshape_input or
134+
self.preprocessor.has_multi_infer_transformations or
135+
getattr(self.reader, 'multi_infer', False)
136+
):
133137
warning('Model can not to be processed in async mode. Switched to sync.')
134138
return self.process_dataset_sync(stored_predictions, progress_reporter, *args, **kwargs)
135139

tools/accuracy_checker/accuracy_checker/evaluators/quantization_model_evaluator.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def completion_callback(status_code, request_id):
107107

108108
self._prepare_to_evaluation(dataset_tag, dump_prediction_to_annotation)
109109

110-
if self.launcher.allow_reshape_input or self.preprocessor.has_multi_infer_transformations:
110+
if (
111+
self.launcher.allow_reshape_input or
112+
self.preprocessor.has_multi_infer_transformations or
113+
self.dataset.multi_infer
114+
):
111115
warning('Model can not to be processed in async mode. Switched to sync.')
112116
return self.process_dataset(
113117
subset,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
models:
2+
- name: weld-porosity-detection-0001
3+
launchers:
4+
- framework: dlsdk
5+
tags:
6+
- FP32
7+
model: intel/weld-porosity-detection-0001/FP32/weld-porosity-detection-0001.xml
8+
weights: intel/weld-porosity-detection-0001/FP32/weld-porosity-detection-0001.bin
9+
adapter: classification
10+
11+
- framework: dlsdk
12+
tags:
13+
- FP16
14+
model: intel/weld-porosity-detection-0001/FP16/weld-porosity-detection-0001.xml
15+
weights: intel/weld-porosity-detection-0001/FP16/weld-porosity-detection-0001.bin
16+
adapter: classification
17+
18+
datasets:
19+
- name: weld-porosity
20+
reader:
21+
type: opencv_imread
22+
multi_infer: True
23+
24+
preprocessing:
25+
- type: resize
26+
size: 224
27+
aspect_ratio_scale: greater
28+
- type: crop
29+
size: 224
30+
31+
metrics:
32+
- type: accuracy
33+
34+
global_definitions: ../dataset_definitions.yml

tools/accuracy_checker/tests/test_model_evaluator.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def setup_method(self):
157157

158158
self.dataset = MagicMock()
159159
self.dataset.__iter__.return_value = [(range(1), self.annotations[0]), (range(1), self.annotations[1])]
160+
self.data_reader.multi_infer = False
160161

161162
self.postprocessor.process_batch = Mock(side_effect=[
162163
([annotation_container_0], [annotation_container_0]), ([annotation_container_1], [annotation_container_1])
@@ -238,7 +239,7 @@ def test_switch_to_sync_predict_if_need_reshaping(self):
238239
assert not self.launcher.predict_async.called
239240
assert self.metric.update_metrics_on_batch.call_count == len(self.annotations)
240241

241-
def test_switch_to_sync_predict_if_need_multi_infer(self):
242+
def test_switch_to_sync_predict_if_need_multi_infer_after_preprocessing(self):
242243
self.postprocessor.has_dataset_processors = False
243244
self.launcher.allow_reshape_input = False
244245
self.preprocessor.has_multi_infer_transformations = True
@@ -250,3 +251,17 @@ def test_switch_to_sync_predict_if_need_multi_infer(self):
250251
assert self.launcher.predict.called
251252
assert not self.launcher.predict_async.called
252253
assert self.metric.update_metrics_on_batch.call_count == len(self.annotations)
254+
255+
def test_switch_to_sync_predict_if_need_multi_infer(self):
256+
self.postprocessor.has_dataset_processors = False
257+
self.launcher.allow_reshape_input = False
258+
self.preprocessor.has_multi_infer_transformations = False
259+
self.data_reader.multi_infer = True
260+
261+
self.evaluator.process_dataset(None, None)
262+
263+
assert not self.evaluator.store_predictions.called
264+
assert not self.evaluator.load.called
265+
assert self.launcher.predict.called
266+
assert not self.launcher.predict_async.called
267+
assert self.metric.update_metrics_on_batch.call_count == len(self.annotations)

0 commit comments

Comments
 (0)