From bbd221e6d3200c055f2ed59c1b64371eb21bcc71 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Mon, 14 Nov 2022 10:51:27 +0100 Subject: [PATCH] [PyOV] Fix compatibility if-ops test (#13952) --- .../tests/test_runtime/test_compiled_model.py | 5 ++- .../python/tests/test_runtime/test_core.py | 4 +-- .../tests/test_runtime/test_function.py | 2 +- .../tests/test_runtime/test_infer_request.py | 5 ++- .../python/tests/test_runtime/test_tensor.py | 2 +- .../python/tests_compatibility/__init__.py | 1 - .../test_inference_engine/test_Blob.py | 2 +- .../test_ExecutableNetwork.py | 2 +- .../test_InferRequest.py | 2 +- .../test_ngraph/test_if.py | 5 --- .../test_utils/test_utils.py | 36 ++++++++----------- 11 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/bindings/python/tests/test_runtime/test_compiled_model.py b/src/bindings/python/tests/test_runtime/test_compiled_model.py index c3582cfb6a0..7a0737c158a 100644 --- a/src/bindings/python/tests/test_runtime/test_compiled_model.py +++ b/src/bindings/python/tests/test_runtime/test_compiled_model.py @@ -6,9 +6,8 @@ import os import pytest import numpy as np -# TODO: refactor into absolute paths -from ..conftest import model_path -from ..test_utils.test_utils import generate_image +from tests.conftest import model_path +from tests.test_utils.test_utils import generate_image from openvino.runtime import Model, ConstOutput, Shape from openvino.runtime import Core, Tensor diff --git a/src/bindings/python/tests/test_runtime/test_core.py b/src/bindings/python/tests/test_runtime/test_core.py index c6b608f333f..55e0b9b1e77 100644 --- a/src/bindings/python/tests/test_runtime/test_core.py +++ b/src/bindings/python/tests/test_runtime/test_core.py @@ -20,14 +20,14 @@ from openvino.runtime import ( compile_model, ) -from ..conftest import ( +from tests.conftest import ( model_path, model_onnx_path, plugins_path, get_model_with_template_extension, ) -from ..test_utils.test_utils import ( +from tests.test_utils.test_utils import ( generate_image, generate_relu_model, ) diff --git a/src/bindings/python/tests/test_runtime/test_function.py b/src/bindings/python/tests/test_runtime/test_function.py index e0f6541518a..dc59d4ef116 100644 --- a/src/bindings/python/tests/test_runtime/test_function.py +++ b/src/bindings/python/tests/test_runtime/test_function.py @@ -22,7 +22,7 @@ from openvino.runtime import ( serialize, ) -from tests.test_utils.test_utils import generate_add_model, create_filename_for_test # TODO: reformat into an absolute path +from tests.test_utils.test_utils import generate_add_model, create_filename_for_test def test_test_descriptor_tensor(): diff --git a/src/bindings/python/tests/test_runtime/test_infer_request.py b/src/bindings/python/tests/test_runtime/test_infer_request.py index 4ecd8800ad9..2cc0b81a88c 100644 --- a/src/bindings/python/tests/test_runtime/test_infer_request.py +++ b/src/bindings/python/tests/test_runtime/test_infer_request.py @@ -15,9 +15,8 @@ from openvino.runtime import Core, AsyncInferQueue, Tensor, ProfilingInfo, Model from openvino.runtime import Type, PartialShape, Shape, Layout from openvino.preprocess import PrePostProcessor -# TODO: reformat into absolute paths -from ..conftest import model_path -from ..test_utils.test_utils import generate_image +from tests.conftest import model_path +from tests.test_utils.test_utils import generate_image is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD" test_net_xml, test_net_bin = model_path(is_myriad) diff --git a/src/bindings/python/tests/test_runtime/test_tensor.py b/src/bindings/python/tests/test_runtime/test_tensor.py index b17a2b89359..e012a76c4b1 100644 --- a/src/bindings/python/tests/test_runtime/test_tensor.py +++ b/src/bindings/python/tests/test_runtime/test_tensor.py @@ -14,7 +14,7 @@ from openvino.helpers import pack_data, unpack_data import pytest -from ..test_utils.test_utils import generate_image # TODO: reformat into an absolute path +from tests.test_utils.test_utils import generate_image @pytest.mark.parametrize(("ov_type", "numpy_dtype"), [ diff --git a/src/bindings/python/tests_compatibility/__init__.py b/src/bindings/python/tests_compatibility/__init__.py index 6926b44b082..c4d65e6fd53 100644 --- a/src/bindings/python/tests_compatibility/__init__.py +++ b/src/bindings/python/tests_compatibility/__init__.py @@ -141,7 +141,6 @@ xfail_issue_81976 = xfail_test(reason="RuntimeError: z node not found in graph c xfail_issue_82038 = xfail_test(reason="ScatterElements, ScatterND, AssertionError: Result mismatch") xfail_issue_82039 = xfail_test(reason="Unsupported data type Optional, RuntimeError: [ NOT_IMPLEMENTED ] " "CPU plugin: Input image format UNSPECIFIED is not supported yet...") -skip_issue_86384 = pytest.mark.skip(reason="If op compatibility tests failing only when triggering whole test suite") xfail_issue_90649 = xfail_test(reason="RuntimeError: OV does not support the following ONNX operations:" "BlackmanWindow, DFT, HammingWindow, HannWindow, LayerNormalization, " "MelWeightMatrix, SequenceMap, STFT") diff --git a/src/bindings/python/tests_compatibility/test_inference_engine/test_Blob.py b/src/bindings/python/tests_compatibility/test_inference_engine/test_Blob.py index fb2722cfc9b..2a9159ac48b 100644 --- a/src/bindings/python/tests_compatibility/test_inference_engine/test_Blob.py +++ b/src/bindings/python/tests_compatibility/test_inference_engine/test_Blob.py @@ -8,7 +8,7 @@ import os from openvino.inference_engine import TensorDesc, Blob, IECore from tests_compatibility.conftest import model_path -from ..test_utils.test_utils import generate_image # TODO: reformat into an absolute path +from tests_compatibility.test_utils.test_utils import generate_image def test_init_with_tensor_desc(): diff --git a/src/bindings/python/tests_compatibility/test_inference_engine/test_ExecutableNetwork.py b/src/bindings/python/tests_compatibility/test_inference_engine/test_ExecutableNetwork.py index 07d14baa0a0..ab61b8b9155 100644 --- a/src/bindings/python/tests_compatibility/test_inference_engine/test_ExecutableNetwork.py +++ b/src/bindings/python/tests_compatibility/test_inference_engine/test_ExecutableNetwork.py @@ -8,7 +8,7 @@ import time from openvino.inference_engine import ie_api as ie from tests_compatibility.conftest import model_path -from ..test_utils.test_utils import generate_image # TODO: reformat into an absolute path +from tests_compatibility.test_utils.test_utils import generate_image is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD" diff --git a/src/bindings/python/tests_compatibility/test_inference_engine/test_InferRequest.py b/src/bindings/python/tests_compatibility/test_inference_engine/test_InferRequest.py index 95ea512da7c..28333e40552 100644 --- a/src/bindings/python/tests_compatibility/test_inference_engine/test_InferRequest.py +++ b/src/bindings/python/tests_compatibility/test_inference_engine/test_InferRequest.py @@ -10,7 +10,7 @@ import time from openvino.inference_engine import ie_api as ie from tests_compatibility.conftest import model_path, create_encoder -from ..test_utils.test_utils import generate_image # TODO: reformat into an absolute path +from tests_compatibility.test_utils.test_utils import generate_image import ngraph as ng from ngraph.impl import Function, Type diff --git a/src/bindings/python/tests_compatibility/test_ngraph/test_if.py b/src/bindings/python/tests_compatibility/test_ngraph/test_if.py index f13cb364156..daab62b855d 100644 --- a/src/bindings/python/tests_compatibility/test_ngraph/test_if.py +++ b/src/bindings/python/tests_compatibility/test_ngraph/test_if.py @@ -9,7 +9,6 @@ from ngraph.utils.tensor_iterator_types import ( TensorIteratorInvariantInputDesc, TensorIteratorBodyOutputDesc, ) -from tests_compatibility import skip_issue_86384 from tests_compatibility.runtime import get_runtime @@ -151,7 +150,6 @@ def check_if(if_model, cond_val, exp_results): check_results(results, exp_results) -@skip_issue_86384 def test_if_with_two_outputs(): check_if(create_simple_if_with_two_outputs, True, [np.array([10], dtype=np.float32), np.array([-20], dtype=np.float32)]) @@ -159,7 +157,6 @@ def test_if_with_two_outputs(): [np.array([17], dtype=np.float32), np.array([16], dtype=np.float32)]) -@skip_issue_86384 def test_diff_if_with_two_outputs(): check_if(create_diff_if_with_two_outputs, True, [np.array([10], dtype=np.float32), np.array([6, 4], dtype=np.float32)]) @@ -167,13 +164,11 @@ def test_diff_if_with_two_outputs(): [np.array([4], dtype=np.float32), np.array([12, 16], dtype=np.float32)]) -@skip_issue_86384 def test_simple_if(): check_if(simple_if, True, [np.array([6, 4], dtype=np.float32)]) check_if(simple_if, False, [np.array([5, 5], dtype=np.float32)]) -@skip_issue_86384 def test_simple_if_without_body_parameters(): check_if(simple_if_without_parameters, True, [np.array([0.7], dtype=np.float32)]) check_if(simple_if_without_parameters, False, [np.array([9.0], dtype=np.float32)]) diff --git a/src/bindings/python/tests_compatibility/test_utils/test_utils.py b/src/bindings/python/tests_compatibility/test_utils/test_utils.py index 83194f59803..f1789b53f61 100644 --- a/src/bindings/python/tests_compatibility/test_utils/test_utils.py +++ b/src/bindings/python/tests_compatibility/test_utils/test_utils.py @@ -2,42 +2,36 @@ # SPDX-License-Identifier: Apache-2.0 import openvino -from openvino.runtime import Model, Core, Shape, Type -from openvino.runtime.op import Parameter +import ngraph as ng +from openvino.inference_engine import IECore, IENetwork +from ngraph.impl import Function, Shape, Type +from ngraph.impl.op import Parameter + from typing import Tuple, Union, List -import openvino.runtime.opset8 as ops import numpy as np def get_test_function(): element_type = Type.f32 param = Parameter(element_type, Shape([1, 3, 22, 22])) - relu = ops.relu(param) - func = Model([relu], [param], "test") + relu = ng.relu(param) + func = Function([relu], [param], "test") assert func is not None return func -def test_compare_functions(): - try: - from openvino.test_utils import compare_functions - func = get_test_function() - status, _ = compare_functions(func, func) - assert status - except ModuleNotFoundError: - print("openvino.test_utils.compare_functions is not available") - - def generate_image(shape: Tuple = (1, 3, 32, 32), dtype: Union[str, np.dtype] = "float32") -> np.array: np.random.seed(42) return np.random.rand(*shape).astype(dtype) -def generate_model(input_shape: List[int]) -> openvino.runtime.ie_api.CompiledModel: - param = ops.parameter(input_shape, np.float32, name="parameter") - relu = ops.relu(param, name="relu") - func = Model([relu], [param], "test") +def generate_model(input_shape: List[int]) -> openvino.inference_engine.ExecutableNetwork: + param = ng.parameter(input_shape, np.float32, name="parameter") + relu = ng.relu(param, name="relu") + func = Function([relu], [param], "test") func.get_ordered_ops()[2].friendly_name = "friendly" - core = Core() - return core.compile_model(func, "CPU", {}) + core = IECore() + caps = Function.to_capsule(func) + cnnNetwork = IENetwork(caps) + return core.load_network(cnnNetwork, "CPU", {})