Skip to content

Commit 8441861

Browse files
authored
AC: support openvino 2.0 launcher (#2898)
1 parent 146a73b commit 8441861

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

+2021
-282
lines changed

tools/accuracy_checker/.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ disable = C0103,
2222
max-line-length = 120
2323
ignore-docstrings = yes
2424
extension-pkg-whitelist=inference_engine,cv2,numpy,mxnet,tensorflow,pycocotools,onnxruntime,kenlm,paddle,torchvision
25-
ignored-modules = numpy,cv2,openvino.inference_engine,caffe,mxnet,tensorflow,pycocotools,onnxruntime,torch,kenlm,paddle.fluid.core,torchvision
25+
ignored-modules = numpy,cv2,openvino.inference_engine,caffe,mxnet,tensorflow,pycocotools,onnxruntime,torch,kenlm,paddle.fluid.core,torchvision,openvino.pyopenvino,openvino.ie_api,openvino.impl
2626
load-plugins = pylint_checkers
2727
ignored-classes = pathlib.PurePath
2828
jobs=0

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from .reidentification import ReidAdapter
5252
from .detection import (
5353
TFObjectDetectionAPIAdapter,
54-
MTCNNPAdapter,
5554
ClassAgnosticDetectionAdapter,
5655
FaceBoxesAdapter,
5756
FaceDetectionAdapter,
@@ -62,6 +61,7 @@
6261
UltraLightweightFaceDetectionAdapter,
6362
PPDetectionAdapter
6463
)
64+
from .mtcnn import MTCNNPAdapter
6565
from .detection_person_vehicle import (
6666
PersonVehicleDetectionAdapter,
6767
PersonVehicleDetectionRefinementAdapter
@@ -133,7 +133,6 @@
133133
'ClassificationAdapter',
134134

135135
'TFObjectDetectionAPIAdapter',
136-
'MTCNNPAdapter',
137136
'CTDETAdapter',
138137
'RetinaNetAdapter',
139138
'RetinaNetTF2',
@@ -152,6 +151,7 @@
152151
'UltraLightweightFaceDetectionAdapter',
153152
'PPDetectionAdapter',
154153
'FacialLandmarksAdapter',
154+
'MTCNNPAdapter',
155155

156156
'TinyYOLOv1Adapter',
157157
'YoloV2Adapter',

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/action_recognition.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,18 @@ def find_layer(regex, output_name, all_outputs):
297297

298298
self.loc_out = find_layer(loc_out_regex, 'loc', raw_outputs)
299299
self.main_conf_out = find_layer(main_conf_out_regex, 'main confidence', raw_outputs)
300+
self.outputs_verified = True
301+
if contains_all(raw_outputs, self.add_conf_outs):
302+
return
303+
add_conf_result = [layer_name + '/sink_port_0' for layer_name in self.add_conf_outs]
304+
if contains_all(raw_outputs, add_conf_result):
305+
self.add_conf_outs = add_conf_result
306+
return
300307
add_conf_with_bias = [layer_name + '/add_' for layer_name in self.add_conf_outs]
301-
if not contains_all(raw_outputs, self.add_conf_outs) and contains_all(raw_outputs, add_conf_with_bias):
308+
if contains_all(raw_outputs, add_conf_with_bias):
302309
self.add_conf_outs = add_conf_with_bias
303-
304-
self.outputs_verified = True
310+
return
311+
add_conf_with_bias_result = [layer_name + '/add_/sink_port_0' for layer_name in self.add_conf_outs]
312+
if contains_all(raw_outputs, add_conf_with_bias_result):
313+
self.add_conf_outs = add_conf_with_bias_result
314+
return

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/adapter.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ def process(self, raw, identifiers, frame_meta):
5151
def configure(self):
5252
pass
5353

54+
@staticmethod
55+
def check_output_name(output_name, outputs, suffix='/sink_port_0'):
56+
outputs = outputs[0] if isinstance(outputs, list) else outputs
57+
if output_name in outputs:
58+
return output_name
59+
if suffix in output_name:
60+
preprocessed_output_name = output_name.replace(suffix, '')
61+
else:
62+
preprocessed_output_name = '{}{}'.format(output_name, suffix)
63+
if preprocessed_output_name in outputs:
64+
return preprocessed_output_name
65+
return output_name
66+
5467
@classmethod
5568
def validate_config(cls, config, fetch_only=False, uri_prefix='', **kwargs):
5669
if cls.__name__ == Adapter.__name__:

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/attribute_classification.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ def parameters(cls):
4242
def configure(self):
4343
super().configure()
4444
self.output_layers = self.get_value_from_config('output_layer_map')
45+
self.outputs_verified = False
4546

4647
@classmethod
4748
def validate_config(cls, config, fetch_only=False, **kwargs):
4849
return super().validate_config(
4950
config, fetch_only=fetch_only, on_extra_argument=ConfigValidator.ERROR_ON_EXTRA_ARGUMENT
5051
)
5152

53+
def select_output_blob(self, outputs):
54+
new_output_layers = {}
55+
for attr, layer_name in self.output_layers.items():
56+
new_output_layers[attr] = self.check_output_name(layer_name, outputs)
57+
self.output_layers = new_output_layers
58+
self.outputs_verified = True
59+
5260
def process(self, raw, identifiers, frame_meta):
5361
"""
5462
Args:
@@ -61,6 +69,8 @@ def process(self, raw, identifiers, frame_meta):
6169
result = []
6270
if isinstance(raw, dict):
6371
raw = [raw]
72+
if not self.outputs_verified:
73+
self.select_output_blob(raw)
6474
for identifier, raw_output in zip(identifiers, raw):
6575
container_dict = {}
6676
for layer_name, attribute in self.output_layers.items():

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/attributes_recognition.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def configure(self):
5959
self.angle_yaw = self.get_value_from_config('angle_yaw')
6060
self.angle_pitch = self.get_value_from_config('angle_pitch')
6161
self.angle_roll = self.get_value_from_config('angle_roll')
62+
self.outputs_verified = False
6263

6364
def process(self, raw, identifiers, frame_meta):
6465
"""
@@ -71,6 +72,8 @@ def process(self, raw, identifiers, frame_meta):
7172
"""
7273
result = []
7374
raw_output = self._extract_predictions(raw, frame_meta)
75+
if not self.outputs_verified:
76+
self.select_output_blob(raw_output)
7477
for identifier, yaw, pitch, roll in zip(
7578
identifiers,
7679
raw_output[self.angle_yaw],
@@ -86,6 +89,12 @@ def process(self, raw, identifiers, frame_meta):
8689

8790
return result
8891

92+
def select_output_blob(self, outputs):
93+
self.check_output_name(self.angle_yaw, outputs)
94+
self.check_output_name(self.angle_pitch, outputs)
95+
self.check_output_name(self.angle_roll, outputs)
96+
self.outputs_verified = True
97+
8998

9099
class VehicleAttributesRecognitionAdapter(Adapter):
91100
__provider__ = 'vehicle_attributes'
@@ -112,10 +121,13 @@ def configure(self):
112121
"""
113122
self.color_out = self.get_value_from_config('color_out')
114123
self.type_out = self.get_value_from_config('type_out')
124+
self.outputs_verified = False
115125

116126
def process(self, raw, identifiers=None, frame_meta=None):
117127
res = []
118128
raw_output = self._extract_predictions(raw, frame_meta)
129+
if not self.outputs_verified:
130+
self.select_output_blob(raw_output)
119131
for identifier, colors, types in zip(identifiers, raw_output[self.color_out], raw_output[self.type_out]):
120132
res.append(ContainerPrediction({
121133
'color': ClassificationPrediction(identifier, colors.reshape(-1)),
@@ -124,6 +136,11 @@ def process(self, raw, identifiers=None, frame_meta=None):
124136

125137
return res
126138

139+
def select_output_blob(self, outputs):
140+
self.check_output_name(self.color_out, outputs)
141+
self.check_output_name(self.type_out, outputs)
142+
self.outputs_verified = True
143+
127144

128145
class AgeGenderAdapter(Adapter):
129146
__provider__ = 'age_gender'
@@ -141,6 +158,7 @@ def parameters(cls):
141158
def configure(self):
142159
self.age_out = self.get_value_from_config('age_out')
143160
self.gender_out = self.get_value_from_config('gender_out')
161+
self.outputs_verified = False
144162

145163
@classmethod
146164
def validate_config(cls, config, fetch_only=False, **kwargs):
@@ -166,6 +184,8 @@ def get_age_scores(age):
166184
def process(self, raw, identifiers=None, frame_meta=None):
167185
result = []
168186
raw_output = self._extract_predictions(raw, frame_meta)
187+
if not self.outputs_verified:
188+
self.select_output_blob(raw_output)
169189
for identifier, age, gender in zip(identifiers, raw_output[self.age_out], raw_output[self.gender_out]):
170190
gender = gender.reshape(-1)
171191
age = age.reshape(-1)[0]*100
@@ -178,6 +198,11 @@ def process(self, raw, identifiers=None, frame_meta=None):
178198

179199
return result
180200

201+
def select_output_blob(self, outputs):
202+
self.age_out = self.check_output_name(self.age_out, outputs)
203+
self.gender_out = self.check_output_name(self.gender_out, outputs)
204+
self.outputs_verified = True
205+
181206

182207
class AgeRecognitionAdapter(Adapter):
183208
__provider__ = 'age_recognition'
@@ -193,6 +218,7 @@ def parameters(cls):
193218

194219
def configure(self):
195220
self.age_out = self.get_value_from_config('age_out')
221+
self.output_verified = False
196222

197223
@classmethod
198224
def validate_config(cls, config, fetch_only=False, **kwargs):
@@ -218,8 +244,8 @@ def get_age_scores(age):
218244
def process(self, raw, identifiers=None, frame_meta=None):
219245
result = []
220246
raw_output = self._extract_predictions(raw, frame_meta)
221-
self.select_output_blob(raw_output)
222-
self.age_out = self.age_out or self.output_blob
247+
if not self.output_verified:
248+
self.select_output_blob(raw_output)
223249
prediction = raw_output[self.age_out]
224250
for identifier, output in zip(identifiers, prediction):
225251
age = np.argmax(output)
@@ -231,6 +257,15 @@ def process(self, raw, identifiers=None, frame_meta=None):
231257

232258
return result
233259

260+
def select_output_blob(self, outputs):
261+
self.output_verified = True
262+
if self.age_out:
263+
self.age_out = self.check_output_name(self.age_out, outputs)
264+
return
265+
super().select_output_blob(outputs)
266+
self.age_out = self.output_blob
267+
return
268+
234269

235270
class LandmarksRegressionAdapter(Adapter):
236271
__provider__ = 'landmarks_regression'

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/audio_recognition.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ def configure(self):
9191
self.classification_out = self.get_value_from_config('classification_out')
9292
self.alphabet = ' ' + string.ascii_lowercase + '\'-'
9393
self.alphabet = self.alphabet.encode('ascii').decode('utf-8')
94+
self.output_verified = False
9495

9596
def process(self, raw, identifiers=None, frame_meta=None):
96-
if self.classification_out is not None:
97-
self.output_blob = self.classification_out
97+
if not self.output_verified:
98+
self.select_output_blob(raw)
9899
multi_infer = frame_meta[-1].get('multi_infer', False) if frame_meta else False
99100

100101
raw_output = self._extract_predictions(raw, frame_meta)
@@ -195,6 +196,15 @@ def decode(probabilities, beamwidth=10, blank_id=None):
195196

196197
return res
197198

199+
def select_output_blob(self, outputs):
200+
self.output_verified = True
201+
if self.classification_out:
202+
self.classification_out = self.check_output_name(self.classification_out, outputs)
203+
return
204+
super().select_output_blob(outputs)
205+
self.classification_out = self.output_blob
206+
return
207+
198208

199209
class CTCGreedyDecoder(Adapter):
200210
__provider__ = 'ctc_greedy_decoder'
@@ -217,6 +227,16 @@ def configure(self):
217227
self.alphabet = self.get_value_from_config('alphabet') or ' ' + string.ascii_lowercase + '\'-'
218228
self.softmaxed_probabilities = self.launcher_config.get('softmaxed_probabilities')
219229
self.classification_out = self.get_value_from_config('classification_out')
230+
self.output_verified = False
231+
232+
def select_output_blob(self, outputs):
233+
self.output_verified = True
234+
if self.classification_out:
235+
self.classification_out = self.check_output_name(self.classification_out, outputs)
236+
return
237+
super().select_output_blob(outputs)
238+
self.classification_out = self.output_blob
239+
return
220240

221241
@staticmethod
222242
def _extract_predictions(outputs_list, meta):
@@ -232,8 +252,8 @@ def _extract_predictions(outputs_list, meta):
232252
return output_map
233253

234254
def process(self, raw, identifiers, frame_meta):
235-
if self.classification_out is not None:
236-
self.output_blob = self.classification_out
255+
if not self.output_verified:
256+
self.select_output_blob(raw)
237257
multi_infer = frame_meta[-1].get('multi_infer', False) if frame_meta else False
238258

239259
raw_output = self._extract_predictions(raw, frame_meta)
@@ -357,6 +377,16 @@ def configure(self):
357377
if self.sep not in self.alphabet and self.sep != '':
358378
raise ValueError("\"sep\" must be in alphabet or be an empty string")
359379
self.init_lm(lm_file, lm_vocabulary_offset, lm_vocabulary_length)
380+
self.output_verified = False
381+
382+
def select_output_blob(self, outputs):
383+
self.output_verified = True
384+
if self.probability_out:
385+
self.probability_out = self.check_output_name(self.probability_out, outputs)
386+
return
387+
super().select_output_blob(outputs)
388+
self.probability_out = self.output_blob
389+
return
360390

361391
@staticmethod
362392
def load_python_modules():
@@ -377,6 +407,8 @@ def init_lm(self, lm_file, lm_vocabulary_offset, lm_vocabulary_length):
377407
raise ValueError("Need lm_alpha and lm_beta to use lm_file")
378408

379409
def process(self, raw, identifiers=None, frame_meta=None):
410+
if not self.output_verified:
411+
self.select_output_blob(raw)
380412
log_prob = self._extract_predictions(raw, frame_meta)
381413
log_prob = np.concatenate(list(log_prob))
382414
if not self.logarithmic_prob:

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/centernet.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def configure(self):
4242
self.center_heatmap_out = self.get_value_from_config('center_heatmap_out')
4343
self.width_height_out = self.get_value_from_config('width_height_out')
4444
self.regression_out = self.get_value_from_config('regression_out')
45+
self.outpus_verified = False
46+
47+
def select_output_blob(self, outputs):
48+
self.center_heatmap_out = self.check_output_name(self.center_heatmap_out, outputs)
49+
self.width_height_out = self.check_output_name(self.width_height_out, outputs)
50+
self.regression_out = self.check_output_name(self.regression_out, outputs)
51+
self.outpus_verified = True
4552

4653
@staticmethod
4754
def _gather_feat(feat, ind):
@@ -125,6 +132,8 @@ def _transform(dets, center, scale, height, width):
125132
def process(self, raw, identifiers, frame_meta):
126133
result = []
127134
predictions_batch = self._extract_predictions(raw, frame_meta)
135+
if not self.outpus_verified:
136+
self.select_output_blob(predictions_batch)
128137
hm_batch = predictions_batch[self.center_heatmap_out]
129138
wh_batch = predictions_batch[self.width_height_out]
130139
reg_batch = predictions_batch[self.regression_out]

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/classification.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def configure(self):
5959
self.fixed_output = self.get_value_from_config('fixed_output')
6060
self.fixed_output_index = int(self.get_value_from_config('fixed_output_index'))
6161
self.label_as_array = self.get_value_from_config('label_as_array')
62+
self.output_verified = False
63+
64+
def select_output_blob(self, outputs):
65+
self.output_verified = True
66+
if self.classification_out:
67+
self.classification_out = self.check_output_name(self.classification_out, outputs)
68+
return
69+
super().select_output_blob(outputs)
70+
self.classification_out = self.output_blob
71+
return
6272

6373
def process(self, raw, identifiers, frame_meta):
6474
"""
@@ -69,8 +79,8 @@ def process(self, raw, identifiers, frame_meta):
6979
Returns:
7080
list of ClassificationPrediction objects
7181
"""
72-
if self.classification_out is not None:
73-
self.output_blob = self.classification_out
82+
if not self.output_verified:
83+
self.select_output_blob(raw)
7484
multi_infer = frame_meta[-1].get('multi_infer', False) if frame_meta else False
7585
raw_prediction = self._extract_predictions(raw, frame_meta)
7686
self.select_output_blob(raw_prediction)

tools/accuracy_checker/openvino/tools/accuracy_checker/adapters/ctpn.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,16 @@ def configure(self):
8181
[0, -91, 15, 106],
8282
[0, -134, 15, 149]
8383
])
84+
self.outputs_verified = False
85+
86+
def select_output_blob(self, outputs):
87+
self.cls_prob_out = self.check_output_name(self.cls_prob_out, outputs)
88+
self.bbox_pred_out = self.check_output_name(self.bbox_pred_out, outputs)
89+
self.outputs_verified = True
8490

8591
def process(self, raw, identifiers, frame_meta):
92+
if not self.outputs_verified:
93+
self.select_output_blob(raw)
8694
raw_outputs = self._extract_predictions(raw, frame_meta)
8795
result = []
8896
data = zip(raw_outputs[self.bbox_pred_out], raw_outputs[self.cls_prob_out], frame_meta, identifiers)

0 commit comments

Comments
 (0)