Skip to content

Commit 07f167f

Browse files
authored
AC: update layout configuration (#3057)
1 parent 2cb332d commit 07f167f

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

tools/accuracy_checker/openvino/tools/accuracy_checker/evaluators/model_evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def from_configs(cls, model_config, delayed_annotation_loading=False):
100100
if not postpone_model_loading:
101101
if input_precision:
102102
launcher.update_input_configuration(input_feeder.inputs_config)
103+
input_feeder.update_layout_configuration(launcher.layout_mapping)
103104
preprocessor.input_shapes = launcher.inputs_info_for_meta()
104105
postprocessor = PostprocessingExecutor(dataset_config.get('postprocessing'), dataset_name, dataset_metadata)
105106
metric_dispatcher = None

tools/accuracy_checker/openvino/tools/accuracy_checker/launcher/input_feeder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,5 +545,17 @@ def provide_input_config_for_not_config(
545545
inputs_entry.append(input_config)
546546
return inputs_entry
547547

548+
def update_layout_configuration(self, layout_mapping, override=False):
549+
for layer_name, layout in layout_mapping.items():
550+
if layer_name in self.layouts_mapping:
551+
if not override:
552+
continue
553+
if layout in LAYER_LAYOUT_TO_IMAGE_LAYOUT:
554+
self.layouts_mapping[layer_name] = LAYER_LAYOUT_TO_IMAGE_LAYOUT[layout]
555+
else:
556+
del self.layouts_mapping[layer_name]
557+
elif layout in LAYER_LAYOUT_TO_IMAGE_LAYOUT:
558+
self.layouts_mapping[layer_name] = LAYER_LAYOUT_TO_IMAGE_LAYOUT[layout]
559+
548560
def release(self):
549561
del self.network_inputs

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ def update_input_configuration(self, input_config):
295295
def name(self):
296296
return self.__provider__
297297

298+
@property
299+
def layout_mapping(self):
300+
return {}
301+
298302

299303
def unsupported_launcher(name, error_message=None):
300304
class UnsupportedLauncher(Launcher):

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,17 @@ def try_to_set_default_layout(self):
151151
shape = parse_partial_shape(input_node.get_node().partial_shape)
152152
if len(shape) != 4:
153153
continue
154+
if input_node.get_node().layout.has_name('C'):
155+
channel_dim = input_node.get_node().layout.get_index_by_name('C')
156+
if channel_dim in [3, -1]:
157+
self.default_layout = 'NHWC'
158+
return
154159
if shape[-1] in [1, 3, 4]:
155160
self.default_layout = 'NHWC'
156161
return
157162
self.default_layout = 'NCHW'
158163
return
159164

160-
161165
@property
162166
def device(self):
163167
return self._device
@@ -500,16 +504,15 @@ def _create_network(self, input_shapes=None):
500504
if compiled_model:
501505
self.network = None
502506
self.exec_network = self.ie_core.import_model(str(self._model), self._device)
503-
self.original_outputs = list(self.exec_network.outputs.keys())
504-
has_info = hasattr(self.exec_network, 'input_info')
505-
if has_info:
506-
ie_input_info = {name: data.input_data for name, data in self.exec_network.input_info.items()}
507-
else:
508-
ie_input_info = self.exec_network.inputs
509-
first_input = next(iter(ie_input_info))
510-
input_info = ie_input_info[first_input]
511-
batch_pos = input_info.layout.find('N')
512-
self._batch = input_info.shape[batch_pos] if batch_pos != -1 else 1
507+
self.original_outputs = self.exec_network.outputs
508+
ie_input_info = self.exec_network.inputs
509+
input_info = ie_input_info[0]
510+
batch_pos = (
511+
input_info.get_node().layout.get_index_by_name('N')
512+
if input_info.get_node().layout.has_name('N') else -1
513+
)
514+
515+
self._batch = parse_partial_shape(input_info.partial_shape)[batch_pos] if batch_pos != -1 else 1
513516
return
514517
if self._weights is None and self._model.suffix != '.onnx':
515518
self._weights = model_path.parent / (model_path.name.split(model_path.suffix)[0] + '.bin')
@@ -611,9 +614,17 @@ def dyn_batch_only(self):
611614
return True
612615
for input_name in self.dyn_input_layers:
613616
partial_shape = self._partial_shapes[input_name]
617+
num_undef = 0
618+
for i in partial_shape:
619+
if i == -1:
620+
num_undef += 1
621+
if num_undef > 1:
622+
return False
614623
layout = self.inputs[input_name].layout
615-
if str(layout) == '[...]':
624+
if '...' in str(layout):
616625
layout = self.get_layout_from_config(input_name)
626+
else:
627+
layout = str(layout).replace('[', '').replace(']', '').replace(',', '')
617628
if not layout:
618629
return False
619630
for dim, layout_dim in zip(partial_shape, layout):
@@ -628,6 +639,17 @@ def get_layout_from_config(self, input_name):
628639
return input_config.get('layout', '')
629640
return ''
630641

642+
@property
643+
def layout_mapping(self):
644+
def prepare_layout_string(layout):
645+
layout = str(layout)
646+
return layout.replace('[', '').replace(']', '').replace(',', '')
647+
inputs = self.network.inputs if self.network is not None else self.exec_network.inputs
648+
layouts = {}
649+
for input_node in inputs:
650+
layouts[input_node.get_node().friendly_name] = prepare_layout_string(input_node.get_node().layout)
651+
return layouts
652+
631653
def load_ir(self, xml_path, bin_path, log=False):
632654
self._model = xml_path
633655
self._weights = bin_path

0 commit comments

Comments
 (0)