Skip to content

Commit a3763c9

Browse files
authored
AC: port important bugfix for 2022/1 (#3404)
1 parent a9735f7 commit a3763c9

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/launcher/openvino_launcher.py

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
#pylint:disable=no-name-in-module
1717
#pylint:disable=package-absolute-imports
18+
import io
1819
import multiprocessing
1920
from pathlib import Path
2021
import re
@@ -45,28 +46,15 @@
4546

4647

4748
format_map = {
48-
'f32': np.float32,
49-
'i32': np.int32,
50-
'i64': np.int64,
51-
'fp16': np.float16,
52-
'f16': np.float16,
53-
'i16': np.int16,
54-
'u16': np.uint16,
55-
'i8': np.int8,
56-
'u8': np.uint8,
49+
'f32': np.float32, 'i32': np.int32, 'i64': np.int64,
50+
'fp16': np.float16, 'f16': np.float16, 'i16': np.int16, 'u16': np.uint16,
51+
'i8': np.int8, 'u8': np.uint8,
5752
'boolean': np.uint8
5853
}
5954

6055
PRECISION_STR_TO_TYPE = {
61-
'FP32': Type.f32,
62-
'FP16': Type.f16,
63-
'U8': Type.u8,
64-
'U16': Type.u16,
65-
'I8': Type.i8,
66-
'I16': Type.i16,
67-
'I32': Type.i32,
68-
'I64': Type.i64,
69-
'BOOL': Type.boolean
56+
'FP32': Type.f32, 'FP16': Type.f16, 'U8': Type.u8, 'U16': Type.u16, 'I8': Type.i8, 'I16': Type.i16,
57+
'I32': Type.i32, 'I64': Type.i64, 'BOOL': Type.boolean
7058
}
7159

7260

@@ -461,8 +449,7 @@ def _prepare_multi_device(self, log=True):
461449
if 'num_requests' in self.config:
462450
warning(
463451
"number requests already provided in device name specification. "
464-
"'num_requests' option will be ignored."
465-
)
452+
"'num_requests' option will be ignored.")
466453
elif 'num_requests' in self.config and self.config['num_requests'] != 'AUTO':
467454
num_per_device_requests = get_or_parse_value(self.config['num_request'], casting_type=int)
468455
else:
@@ -502,15 +489,15 @@ def _log_versions(self):
502489
for device_name, device_version in versions.items():
503490
print_info(" {device_name} - {descr}: {maj}.{min}.{num}".format(
504491
device_name=device_name, descr=device_version.description, maj=device_version.major,
505-
min=device_version.minor, num=device_version.build_number
506-
))
492+
min=device_version.minor, num=device_version.build_number))
507493

508494
def _create_network(self, input_shapes=None):
509495
model_path = Path(self._model)
510496
compiled_model = model_path.suffix == '.blob'
511497
if compiled_model:
512498
self.network = None
513-
self.exec_network = self.ie_core.import_model(str(self._model), self._device)
499+
with open(str(self._model), 'rb') as f: #pylint:disable=unspecified-encoding
500+
self.exec_network = self.ie_core.import_model(io.BytesIO(f), self._device)
514501
self.original_outputs = self.exec_network.outputs
515502
model_batch = self._get_model_batch_size()
516503
self._batch = model_batch if model_batch is not None else 1
@@ -560,26 +547,29 @@ def _set_batch_size(self, batch_size):
560547
if layer_name in self.const_inputs:
561548
input_shapes[layer_name] = parse_partial_shape(input_node.get_node().partial_shape)
562549
else:
563-
layer_shape = parse_partial_shape(input_node.get_node().partial_shape)
564-
layout = self.inputs[layer_name].layout
565-
if '...' in str(layout):
566-
layout = self.get_layout_from_config(layer_name)
567-
else:
568-
layout = str(layout).replace('[', '').replace(']', '').replace(',', '')
550+
layer_shape = list(parse_partial_shape(input_node.get_node().partial_shape))
551+
layout = self._process_layout(self.inputs[layer_name].layout, layer_name)
569552
batch_pos = layout.find('N')
570553
if batch_pos != -1:
571554
layer_shape[batch_pos] = batch_size
572555
input_shapes[layer_name] = layer_shape
573556
self._reshape_input(input_shapes, batch_size == -1)
574557
self._batch = batch_size
575558

559+
def _process_layout(self, ov_layout, layer_name):
560+
if '...' in str(ov_layout) or ov_layout is None:
561+
ov_layout = self.get_layout_from_config(layer_name)
562+
else:
563+
ov_layout = str(ov_layout).replace('[', '').replace(']', '').replace(',', '')
564+
return ov_layout
565+
576566
def _get_model_batch_size(self):
577567
input_nodes = self.network.inputs if self.network else self.exec_network.inputs
578568
input_info = input_nodes[0]
579-
if '...' in str(input_info.get_node().layout):
580-
layout = self.get_layout_from_config(input_info.get_node().friendly_name)
581-
else:
582-
layout = str(input_info.get_node().layout).replace('[', '').replace(']', '').replace(',', '')
569+
layout = (
570+
self._process_layout(input_info.get_node().layout, input_info.get_node().friendly_name)
571+
or self.default_layout
572+
)
583573
batch_pos = layout.find('N')
584574
if batch_pos != -1:
585575
return parse_partial_shape(input_info.partial_shape)[batch_pos]
@@ -599,7 +589,6 @@ def load_network(self, network=None, log=False, preprocessing=None):
599589
self.dyn_input_layers, self._partial_shapes = self.get_dynamic_inputs(self.network)
600590
self.input_to_tensor_name = self.get_input_tensor_name_mapping(self.network)
601591
self.input_to_index = {inp.get_node().friendly_name: idx for idx, inp in enumerate(self.network.inputs)}
602-
603592
if not self._postpone_input_configuration:
604593
self._set_precision()
605594
self._set_input_shape()
@@ -674,7 +663,7 @@ def dyn_batch_only(self):
674663
if num_undef > 1:
675664
return False
676665
layout = self.inputs[input_name].layout
677-
if '...' in str(layout):
666+
if '...' in str(layout) or layout is None:
678667
layout = self.get_layout_from_config(input_name)
679668
else:
680669
layout = str(layout).replace('[', '').replace(']', '').replace(',', '')
@@ -715,6 +704,8 @@ def read_network(self, model, weights):
715704
network = self.ie_core.read_model(model=str(model), weights=str(weights))
716705
else:
717706
network = self.ie_core.read_model(model=str(model))
707+
self.input_to_tensor_name = self.get_input_tensor_name_mapping(network)
708+
self.input_to_index = {inp.get_node().friendly_name: idx for idx, inp in enumerate(network.inputs)}
718709
return network
719710

720711
def inputs_info_for_meta(self, inputs=None):
@@ -851,8 +842,7 @@ def _set_precision(self):
851842
if 'precision' in input_config:
852843
if self.network:
853844
self.inputs[input_config['name']].set_element_type(
854-
PRECISION_STR_TO_TYPE[input_config['precision'].upper()]
855-
)
845+
PRECISION_STR_TO_TYPE[input_config['precision'].upper()])
856846

857847
def _set_input_shape(self):
858848
if not self.network:

0 commit comments

Comments
 (0)