Skip to content

Commit d276b46

Browse files
authored
OV2.0 AC: migrate POT evaluator on usage new OV API (#2914)
* AC: migrate POT evaluator on usage new OV API * enable custom evaluators * fix configuration update * fix mtcnn reshape * bugfix * mtcnn remove output renaming * fix sync mode and mtcnn callback * return raw results for callback * experiment with text recognition * fix input output selection * update custom evaluators * fix output selection * properly hanlde renaming * fix num requests * fix text recognition * bump version
1 parent fe2a5a9 commit d276b46

24 files changed

+403
-271
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
limitations under the License.
1515
"""
1616

17-
__version__ = "0.9.1"
17+
__version__ = "0.9.2"

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/image_processing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def configure(self):
7272
self.output_verified = False
7373

7474
def select_output_blob(self, outputs):
75-
self.outputs_verified = True
75+
self.output_verified = True
7676
if not self.target_out:
7777
super().select_output_blob(outputs)
7878
self.target_out = self.output_blob
@@ -114,9 +114,8 @@ class SuperResolutionAdapter(ImageProcessingAdapter):
114114
def process(self, raw, identifiers=None, frame_meta=None):
115115
result = []
116116
raw_outputs = self._extract_predictions(raw, frame_meta)
117-
if not self.outputs_verified:
117+
if not self.output_verified:
118118
self.select_output_blob(raw_outputs)
119-
self.target_out = self.output_blob
120119

121120
for identifier, img_sr in zip(identifiers, raw_outputs[self.target_out]):
122121
img_sr = self._basic_postprocess(img_sr)

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/asr_custom_encoder_decoder_joint.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ def predict(self, identifiers, input_data):
6060
# Evaluate the encoder network one feature frame at a time
6161
data = self.fit_to_input(input_data)
6262
outputs = self.infer(data)
63+
if isinstance(outputs, tuple):
64+
outputs, raw_outputs = outputs
65+
else:
66+
raw_outputs = outputs
6367
encoder_output = np.array(outputs[self.encoder_out]).squeeze()
6468
self.h0 = outputs[self.h0_out]
6569
self.c0 = outputs[self.c0_out]
66-
return encoder_output, outputs
70+
return encoder_output, raw_outputs
6771

6872
def fit_to_input(self, input_data):
6973
return {self.input: input_data, self.h0_input: self.h0, self.c0_input: self.c0}
@@ -117,9 +121,13 @@ def reset(self):
117121
def predict(self, identifiers, input_data, hidden=None):
118122
data = self.fit_to_input(input_data, hidden)
119123
outputs = self.infer(data)
124+
if isinstance(outputs, tuple):
125+
outputs, raw_outputs = outputs
126+
else:
127+
raw_outputs = outputs
120128
self.h0 = outputs[self.h0_out]
121129
self.c0 = outputs[self.c0_out]
122-
return np.array(outputs[self.decoder_out]).squeeze(), (self.h0, self.c0), outputs
130+
return np.array(outputs[self.decoder_out]).squeeze(), (self.h0, self.c0), raw_outputs
123131

124132
def fit_to_input(self, token_id, hidden):
125133
if hidden is None:
@@ -176,8 +184,12 @@ def predict(self, identifiers, input_data):
176184
encoder_out, predictor_out = input_data
177185
data = self.fit_to_input(encoder_out, predictor_out)
178186
outputs = self.infer(data)
187+
if isinstance(outputs, tuple):
188+
outputs, raw_outputs = outputs
189+
else:
190+
raw_outputs = outputs
179191
joint_out = outputs[self.output]
180-
return log_softmax(np.array(joint_out).squeeze()), outputs
192+
return log_softmax(np.array(joint_out).squeeze()), raw_outputs
181193

182194
def fit_to_input(self, encoder_out, predictor_out):
183195
return {self.input1: encoder_out, self.input2: predictor_out}
@@ -282,10 +294,11 @@ def set_input_and_output(self):
282294
]
283295
self.with_prefix = with_prefix
284296

285-
286297
def predict(self, identifiers, input_data):
287298
raise NotImplementedError
288299

300+
def infer(self, input_data, raw_results=False):
301+
return super().infer(input_data, True)
289302

290303

291304
class DLSDKEncoder(Encoder, CommonDLSDKModel):

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/asr_encoder_decoder_evaluator.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ def predict(self, identifiers, input_data, encoder_callback=None):
9696
predictions, raw_outputs = [], []
9797
for data in input_data:
9898
encoder_prediction, decoder_inputs = self.encoder.predict(identifiers, data)
99+
if isinstance(encoder_prediction, tuple):
100+
encoder_prediction, raw_encoder_prediction = encoder_prediction
101+
else:
102+
raw_encoder_prediction = encoder_prediction
99103
if encoder_callback:
100-
encoder_callback(encoder_prediction)
104+
encoder_callback(raw_encoder_prediction)
101105
if self.store_encoder_predictions:
102106
self._encoder_predictions.append(encoder_prediction)
103107
raw_output, prediction = self.decoder.predict(identifiers, decoder_inputs)
@@ -137,8 +141,8 @@ def predict(self, identifiers, input_data):
137141
class EncoderOVModel(BaseOpenVINOModel):
138142
def predict(self, identifiers, input_data):
139143
input_data = self.fit_to_input(input_data)
140-
results = self.infer(input_data)
141-
return results, results[self.output_blob]
144+
results = self.infer(input_data, raw_results=True)
145+
return results, results[self.output_blob] if not isinstance(results, tuple) else results[0][self.output_blob]
142146

143147

144148
class DecoderDLSDKModel(BaseDLSDKModel):
@@ -167,10 +171,10 @@ def __init__(self, network_info, launcher, suffix=None, delayed_model_loading=Fa
167171

168172
def predict(self, identifiers, input_data):
169173
feed_dict = self.fit_to_input(input_data)
170-
results = self.infer(feed_dict)
174+
results, raw_results = self.infer(feed_dict, raw_results=True)
171175
result = self.adapter.process([results], identifiers, [{}])
172176

173-
return results, result
177+
return raw_results, result
174178

175179
def set_input_and_output(self):
176180
super().set_input_and_output()

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/asr_encoder_prediction_joint_evaluator.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from ...adapters import create_adapter
2323
from ...config import ConfigError
24-
from ...utils import contains_all, read_pickle, parse_partial_shape
24+
from ...utils import contains_all, read_pickle, parse_partial_shape, postprocess_output_name
2525
from .asr_encoder_decoder_evaluator import AutomaticSpeechRecognitionEvaluator
2626
from .base_models import (
2727
BaseCascadeModel, BaseDLSDKModel, BaseOpenVINOModel, BaseONNXModel, create_model, create_encoder
@@ -80,8 +80,12 @@ def predict(self, identifiers, input_data, encoder_callback=None):
8080
predictions, raw_outputs = [], []
8181
for data in input_data:
8282
encoder_prediction, decoder_inputs = self.encoder.predict(identifiers, data)
83+
if isinstance(encoder_prediction, tuple):
84+
encoder_prediction, raw_encoder_prediction = encoder_prediction
85+
else:
86+
raw_encoder_prediction = encoder_prediction
8387
if encoder_callback:
84-
encoder_callback(encoder_prediction)
88+
encoder_callback(raw_encoder_prediction)
8589
if self.store_encoder_predictions:
8690
self._encoder_predictions.append(encoder_prediction)
8791
raw_output, prediction = self.decoder(identifiers, decoder_inputs, callback=encoder_callback)
@@ -129,8 +133,12 @@ def _greedy_decode(self, x, out_len, callback=None):
129133
self._get_last_symb(label),
130134
hidden
131135
)
136+
if isinstance(g, tuple):
137+
g, raw_g = g
138+
else:
139+
raw_g = g
132140
if callback:
133-
callback(g)
141+
callback(raw_g)
134142
hidden_prime = (g[self.prediction.output_layers[0]], g[self.prediction.output_layers[1]])
135143
g = g[self.prediction.output_layers[2]]
136144
logp = self._joint_step(f, g, log_normalize=False, callback=callback)[0, :]
@@ -161,8 +169,12 @@ def _pred_step(self, label, hidden):
161169
def _joint_step(self, enc, pred, log_normalize=False, callback=None):
162170
inputs = {self.joint.input_layers[0]: enc, self.joint.input_layers[1]: pred}
163171
logits, logits_blob = self.joint.predict(None, inputs)
172+
if isinstance(logits, tuple):
173+
logits, raw_logits = logits
174+
else:
175+
raw_logits = logits
164176
if callback:
165-
callback(logits)
177+
callback(raw_logits)
166178
logits = logits_blob[:, 0, 0, :]
167179
if not log_normalize:
168180
return logits
@@ -254,8 +266,8 @@ def __init__(self, network_info, launcher, suffix=None, delayed_model_loading=Fa
254266

255267
def predict(self, identifiers, input_data, callback=None):
256268
input_data = self.fit_to_input(input_data)
257-
results = self.infer(input_data)
258-
return results, results[self.output_blob]
269+
results = self.infer(input_data, raw_results=True)
270+
return results, results[self.output_blob] if not isinstance(results, tuple) else results[0][self.output_blob]
259271

260272
def fit_to_input(self, input_data):
261273
if isinstance(input_data, dict):
@@ -278,12 +290,10 @@ def set_input_and_output(self):
278290
with_prefix = input_blob.startswith(self.default_model_suffix)
279291
if self.input_blob is None or with_prefix != self.with_prefix:
280292
if self.output_blob is None:
281-
output_blob = next(iter(self.exec_network.outputs)).get_node().friendly_name
293+
output_blob = next(iter(self.outputs))
282294
else:
283-
output_blob = (
284-
'_'.join([self.default_model_suffix, self.output_blob])
285-
if with_prefix else self.output_blob.split(self.default_model_suffix + '_')[-1]
286-
)
295+
output_blob = postprocess_output_name(self.output_blob, self.outputs, raise_error=False)
296+
287297
self.input_blob = input_blob
288298
self.output_blob = output_blob
289299
self.with_prefix = with_prefix
@@ -292,11 +302,8 @@ def set_input_and_output(self):
292302
'_'.join([self.default_model_suffix, inp])
293303
if with_prefix else inp.split(self.default_model_suffix)[-1]
294304
)
295-
for idx, out in enumerate(self.output_layers):
296-
self.output_layers[idx] = (
297-
'_'.join([self.default_model_suffix, out])
298-
if with_prefix else out.split(self.default_model_suffix)[-1]
299-
)
305+
for idx, out in enumerate(self.output_layers):
306+
self.output_layers[idx] = postprocess_output_name(out, self.outputs, raise_error=False)
300307

301308

302309
class EncoderDLSDKModel(CommonDLSDKModel):

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/base_custom_evaluator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def process_dataset(self, subset=None, num_images=None, check_progress=False, da
5656

5757
if 'progress_reporter' in kwargs:
5858
_progress_reporter = kwargs['progress_reporter']
59-
_progress_reporter.reset(self.dataset.size)
59+
if _progress_reporter is not None:
60+
_progress_reporter.reset(self.dataset.size)
6061
else:
6162
_progress_reporter = None if not check_progress else self._create_progress_reporter(
6263
check_progress, self.dataset.size

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/base_models.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ def _reshape_input(self, input_shapes):
266266
if self.is_dynamic:
267267
return
268268
if hasattr(self, 'exec_network') and self.exec_network is not None:
269-
del self.infer_request
269+
if hasattr(self, 'infer_request'):
270+
del self.infer_request
270271
del self.exec_network
271272
index_mapping = self.input_index_mapping()
272273
input_shapes_for_tensors = {index_mapping[name]: shape for name, shape in input_shapes.items()}
@@ -322,24 +323,24 @@ def set_input_and_output(self):
322323
with_prefix = input_blob.startswith(self.default_model_suffix)
323324
if self.input_blob is None or with_prefix != self.with_prefix:
324325
if self.output_blob is None:
325-
output_blob = next(iter(outputs)).get_node().friendly_name
326-
else:
327-
output_blob = (
328-
'_'.join([self.default_model_suffix, self.output_blob])
329-
if with_prefix else self.output_blob.split(self.default_model_suffix + '_')[-1]
330-
)
326+
self.output_blob = next(iter(outputs)).get_node().friendly_name
331327
self.input_blob = input_blob
332-
self.output_blob = output_blob
333328
self.with_prefix = with_prefix
334329
if hasattr(self, 'adapter') and self.adapter is not None:
335-
self.adapter.output_blob = output_blob
330+
self.adapter.output_blob = self.output_blob
336331

337332
@property
338333
def inputs(self):
339334
if self.network:
340335
return {node.get_node().friendly_name: node.get_node() for node in self.network.inputs}
341336
return {node.get_node().friendly_name: node.get_node() for node in self.exec_network.inputs}
342337

338+
@property
339+
def outputs(self):
340+
if self.network:
341+
return {node.get_node().friendly_name: node.get_node() for node in self.network.outputs}
342+
return {node.get_node().friendly_name: node.get_node() for node in self.exec_network.outputs}
343+
343344
def fit_to_input(self, input_data):
344345
input_info = self.inputs[self.input_blob]
345346
if (self.input_blob in self.dynamic_inputs or
@@ -348,16 +349,19 @@ def fit_to_input(self, input_data):
348349

349350
return {self.input_blob: np.array(input_data)}
350351

351-
def infer(self, input_data):
352+
def infer(self, input_data, raw_results=False):
352353
if not hasattr(self, 'infer_request') or self.infer_request is None:
353354
self.infer_request = self.exec_network.create_infer_request()
354355
tensors_mapping = self.input_tensors_mapping()
355356
feed_dict = {tensors_mapping[name]: data for name, data in input_data.items()}
356357
outputs = self.infer_request.infer(feed_dict)
357-
return {
358+
res_outputs = {
358359
out_node.get_node().friendly_name: out_res
359360
for out_node, out_res in outputs.items()
360361
}
362+
if raw_results:
363+
return res_outputs, outputs
364+
return res_outputs
361365

362366

363367
class BaseONNXModel:

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/cocosnet_evaluator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ def predict(self, identifiers, input_data):
217217
results = []
218218
prediction = None
219219
if self.infer_request is None:
220-
self.infer_request = self.exec_network.create_infer_reuqest()
220+
self.infer_request = self.exec_network.create_infer_request()
221221
for current_input in input_data:
222222
data = self.fit_to_input(current_input)
223223
if not self.is_dynamic and self.dynamic_inputs:
224224
self._reshape_input({k: v.shape for k, v in data.items()})
225-
prediction = self.infer(data)
225+
prediction, raw_prediction = self.infer(data, raw_results=True)
226226
results.append(*self.adapter.process(prediction, identifiers, [{}]))
227-
return results, prediction
227+
return results, raw_prediction
228228

229229

230230
class GanCheckModel(BaseDLSDKModel):

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/custom_evaluators/colorization_evaluator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ def predict(self, identifiers, input_data):
166166
self._inputs[self.input_blob] = img_l_rs
167167
if not self.is_dynamic and self.dynamic_inputs:
168168
self._reshape_input({k: v.shape for k, v in self._inputs.items()})
169-
res = self.infer(self._inputs)
169+
res, raw_res = self.infer(self._inputs, raw_results=True)
170170

171171
new_result = self.postprocessing(res[self.output_blob], img_l)
172-
return res, np.array(new_result)
172+
return raw_res, np.array(new_result)
173173

174174
def set_input_and_output(self):
175175
super().set_input_and_output()
@@ -209,9 +209,9 @@ def predict(self, identifiers, input_data):
209209
input_dict = self.fit_to_input(input_data)
210210
if not self.is_dynamic and self.dynamic_inputs:
211211
self._reshape_input({k: v.shape for k, v in input_dict.items()})
212-
raw_result = self.infer(input_dict)
212+
raw_result, raw_outputs = self.infer(input_dict, raw_results=True)
213213
result = self.adapter.process([raw_result], identifiers, [{}])
214-
return raw_result, result
214+
return raw_outputs, result
215215

216216
def fit_to_input(self, input_data):
217217
constant_normalization = 255.

0 commit comments

Comments
 (0)