From 4f7705689259b0f3deba124c7b0b93d8aeda9654 Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Fri, 10 Dec 2021 12:57:58 +0300 Subject: [PATCH] [PYTHON API]: handle input normalization for tensor without name (#9130) * [PYTHON API]: handle input normalization for tensor without name * remove extra empty line --- src/bindings/python/src/openvino/runtime/ie_api.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bindings/python/src/openvino/runtime/ie_api.py b/src/bindings/python/src/openvino/runtime/ie_api.py index c4a8e7a275c..20945726a65 100644 --- a/src/bindings/python/src/openvino/runtime/ie_api.py +++ b/src/bindings/python/src/openvino/runtime/ie_api.py @@ -25,13 +25,10 @@ def tensor_from_file(path: str) -> Tensor: def normalize_inputs(py_dict: dict, py_types: dict) -> dict: """Normalize a dictionary of inputs to Tensors.""" for k, val in py_dict.items(): + if not isinstance(k, (str, int)): + raise TypeError("Incompatible key type for tensor named: {}".format(k)) try: - if isinstance(k, int): - ov_type = list(py_types.values())[k] - elif isinstance(k, str): - ov_type = py_types[k] - else: - raise TypeError("Incompatible key type for tensor named: {}".format(k)) + ov_type = py_types[k] except KeyError: raise KeyError("Port for tensor named {} was not found!".format(k)) py_dict[k] = ( @@ -49,8 +46,9 @@ def get_input_types(obj: Union[InferRequestBase, ExecutableNetworkBase]) -> dict return {n: input.get_element_type() for n in input.get_names()} input_types: dict = {} - for input in obj.inputs: - input_types = {**input_types, **map_tensor_names_to_types(input)} + for idx, input in enumerate(obj.inputs): + input_types.update(map_tensor_names_to_types(input)) + input_types[idx] = input.get_element_type() return input_types