Skip to content

Commit 1177e3a

Browse files
authored
AC: fix output tenors maring release (#3426)
1 parent 87ac507 commit 1177e3a

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

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

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import warnings
2323
import numpy as np
2424
from openvino.runtime import Core, AsyncInferQueue, get_version, PartialShape, Type, Dimension
25+
from openvino.preprocess import PrePostProcessor
2526
from .dlsdk_launcher_config import (
2627
HETERO_KEYWORD, MULTI_DEVICE_KEYWORD, NIREQ_REGEX, VPU_PLUGINS,
2728
get_cpu_extension,
@@ -494,19 +495,24 @@ def _log_versions(self):
494495
def _create_network(self, input_shapes=None):
495496
model_path = Path(self._model)
496497
compiled_model = model_path.suffix == '.blob'
498+
self.out_tensor_name_to_node = {}
497499
if compiled_model:
498500
self.network = None
499501
with open(str(self._model), 'rb') as f: #pylint:disable=unspecified-encoding
500502
self.exec_network = self.ie_core.import_model(io.BytesIO(f.read()), self._device)
501503
self.original_outputs = self.exec_network.outputs
502504
model_batch = self._get_model_batch_size()
503505
self._batch = model_batch if model_batch is not None else 1
506+
for out in self.original_outputs:
507+
if not out.names:
508+
continue
509+
for name in out.names:
510+
self.out_tensor_name_to_node[name] = out.get_node().friendly_name
504511
return
505512
if self._weights is None and self._model.suffix != '.onnx':
506513
self._weights = model_path.parent / (model_path.name.split(model_path.suffix)[0] + '.bin')
507514
self.network = self.read_network(self._model, self._weights)
508515
self.original_outputs = self.network.outputs
509-
self.out_tensor_name_to_node = {}
510516
for out in self.original_outputs:
511517
if not out.names:
512518
continue
@@ -587,8 +593,10 @@ def load_network(self, network=None, log=False, preprocessing=None):
587593
self.network = network
588594
if self.network is not None:
589595
self.dyn_input_layers, self._partial_shapes = self.get_dynamic_inputs(self.network)
590-
self.input_to_tensor_name = self.get_input_tensor_name_mapping(self.network)
591-
self.input_to_index = {inp.get_node().friendly_name: idx for idx, inp in enumerate(self.network.inputs)}
596+
self.input_to_tensor_name = self.get_input_tensor_name_mapping(
597+
self.network if self.network is not None else self.exec_network)
598+
network_inputs = self.network.inputs if self.network is not None else self.exec_network.inputs
599+
self.input_to_index = {inp.get_node().friendly_name: idx for idx, inp in enumerate(network_inputs)}
592600
if not self._postpone_input_configuration:
593601
self._set_precision()
594602
self._set_input_shape()
@@ -597,12 +605,13 @@ def load_network(self, network=None, log=False, preprocessing=None):
597605
self.print_input_output_info(self.network if self.network is not None else self.exec_network)
598606
if preprocessing:
599607
self._set_preprocess(preprocessing)
608+
self.dyn_input_layers, self._partial_shapes = self.get_dynamic_inputs(self.network)
600609
model_batch = self._get_model_batch_size()
601610
model_batch = 1 if model_batch is None else model_batch
602611
self._batch = self.config.get('batch', model_batch)
603612
self._set_batch_size(self._batch)
604613
self.try_to_set_default_layout()
605-
if self.network and not preprocessing and (not self.dyn_input_layers or self.is_dynamic):
614+
if self.network and (not self.dyn_input_layers or self.is_dynamic or self.disable_resize_to_input):
606615
self.exec_network = self.ie_core.compile_model(self.network, self._device)
607616
self.infer_request = self.exec_network.create_infer_request()
608617

@@ -838,11 +847,15 @@ def _data_to_blob(self, layer_shape, data, layout): # pylint:disable=R0911,R091
838847

839848
def _set_precision(self):
840849
config_inputs = self.config.get('inputs', [])
841-
for input_config in config_inputs:
842-
if 'precision' in input_config:
843-
if self.network:
844-
self.inputs[input_config['name']].set_element_type(
845-
PRECISION_STR_TO_TYPE[input_config['precision'].upper()])
850+
has_precisions = ['precision' in inp for inp in config_inputs]
851+
if has_precisions and self.network:
852+
preprocessor = PrePostProcessor(self.network)
853+
for input_config in config_inputs:
854+
if 'precision' in input_config:
855+
name = input_config['name']
856+
element_type = PRECISION_STR_TO_TYPE[input_config['precision'].upper()]
857+
preprocessor.input(self.input_to_index[name]).tensor().set_element_type(element_type)
858+
self.network = preprocessor.build()
846859

847860
def _set_input_shape(self):
848861
if not self.network:
@@ -914,33 +927,28 @@ def _set_preprocess(self, preprocess):
914927
preprocess_steps = preprocess.ie_preprocess_steps
915928
if not preprocess_steps:
916929
return
917-
for input_name, input_info in self.network.input_info.items():
930+
preprocessor = PrePostProcessor(self.network)
931+
for input_name in self.inputs:
918932
if input_name in self.const_inputs + self.image_info_inputs:
919933
continue
934+
input_id = self.input_to_index[input_name]
920935
for (name, value) in preprocess_steps:
921-
setattr(input_info.preprocess_info, name, value)
922-
if preprocess.ie_processor.has_normalization():
923-
channel_id = input_info.layout.find('C')
924-
if channel_id != -1:
925-
num_channels = input_info.input_data.shape[channel_id]
926-
preprocess.ie_processor.set_normalization(num_channels, input_info.preprocess_info)
927-
self.disable_resize_to_input = preprocess.ie_processor.has_resize()
928-
self._use_set_blob = self.disable_resize_to_input
929-
self.load_network(self.network)
936+
if name == 'resize_algorithm':
937+
preprocessor.input(input_id).tensor().set_spatial_dynamic_shape()
938+
preprocessor.input(input_id).preprocess().resize(value)
939+
self.need_dyn_resolving = False
940+
if name == 'convert_color_format':
941+
src, dst = value
942+
preprocessor.input(input_id).tensor().set_color_format(src)
943+
preprocessor.input(input_id).preprocess().convert_color(dst)
944+
if name == 'mean_variant':
945+
mean, scale = value
946+
if mean is not None:
947+
preprocessor.input(input_id).preprocess().mean(mean)
948+
if scale is not None:
949+
preprocessor.input(input_id).preprocess().scale(scale)
950+
self.network = preprocessor.build()
930951
self._preprocess_steps = preprocess_steps
931-
return
932-
preprocess_info_by_input = {}
933-
preprocess_info = preprocess.preprocess_info
934-
for input_name in self.inputs:
935-
if input_name in self.const_inputs + self.image_info_inputs:
936-
continue
937-
if preprocess.ie_processor.has_normalization():
938-
channel_id = self.inputs[input_name].layout.find('C')
939-
if channel_id != -1:
940-
num_channels = self.inputs[input_name].shape[channel_id]
941-
preprocess.ie_processor.set_normalization(num_channels, preprocess_info)
942-
preprocess_info_by_input[input_name] = preprocess_info
943-
self._preprocess_info = preprocess_info_by_input
944952
self.disable_resize_to_input = preprocess.ie_processor.has_resize()
945953

946954
def get_model_file_type(self):
@@ -958,8 +966,7 @@ def get_infer_queue(self, log=True):
958966
debug('Prepared async infer queue with {} requests'.format(len(queue)))
959967
return queue
960968

961-
def prepare_data_for_request(self,
962-
inputs, batch_meta, batch_id, batch_input_ids,
969+
def prepare_data_for_request(self, inputs, batch_meta, batch_id, batch_input_ids,
963970
batch_annotation, batch_identifiers):
964971
infer_inputs = inputs[0]
965972
feed_dict = {self.input_to_tensor_name[name]: data for name, data in infer_inputs.items()}

0 commit comments

Comments
 (0)