[PyOV] Update imports in py api tests (#21252)

* [PyOV] Update imports in py api tests

* update year and back test_compression_4bit.py

* missed import
This commit is contained in:
Anastasia Kuporosova 2023-11-24 11:16:57 +04:00 committed by GitHub
parent b7edd5df69
commit ccfe58cf84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 355 additions and 356 deletions

View File

@ -2,7 +2,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import OVAny
from openvino import OVAny
import pytest

View File

@ -11,16 +11,17 @@ import openvino.runtime as ov
from openvino import (
Model,
Layout,
PartialShape,
Shape,
Strides,
Tensor,
Type,
OVAny,
layout_helpers,
)
from openvino.runtime.op import Parameter
from openvino.runtime import Strides, AxisVector, Coordinate, CoordinateDiff
from openvino.runtime.op import Parameter, Constant
from openvino.runtime import AxisVector, Coordinate, CoordinateDiff
from openvino._pyopenvino import DescriptorTensor
from openvino.runtime.utils.types import get_element_type
@ -36,8 +37,8 @@ def test_graph_function_api():
assert parameter_a.element_type == Type.f32
assert parameter_b.element_type == Type.f32
assert parameter_a.partial_shape == PartialShape([2, 2])
parameter_a.layout = ov.Layout("NC")
assert parameter_a.layout == ov.Layout("NC")
parameter_a.layout = Layout("NC")
assert parameter_a.layout == Layout("NC")
function = Model(model, [parameter_a, parameter_b, parameter_c], "TestModel")
function.get_parameters()[1].set_partial_shape(PartialShape([3, 4, 5]))
@ -62,8 +63,8 @@ def test_graph_function_api():
assert len(results) == 1
assert results[0].get_output_element_type(0) == Type.f32
assert results[0].get_output_partial_shape(0) == PartialShape([2, 2])
results[0].layout = ov.Layout("NC")
assert results[0].layout.to_string() == ov.Layout("NC")
results[0].layout = Layout("NC")
assert results[0].layout.to_string() == Layout("NC")
assert function.get_friendly_name() == "TestModel"
@ -259,7 +260,7 @@ def test_constant_get_data_unsigned_integer(data_type):
],
)
def test_constant_from_empty_array(shared_flag, init_value):
const = ov.op.Constant(init_value, shared_memory=shared_flag)
const = Constant(init_value, shared_memory=shared_flag)
assert tuple(const.shape) == init_value.shape
assert const.get_element_type().to_dtype() == init_value.dtype
assert const.get_byte_size() == init_value.nbytes
@ -310,8 +311,8 @@ def test_clone_model():
shape = [2, 2]
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
parameter_b = ops.parameter(shape, dtype=np.float32, name="B")
model_original = ov.Model(parameter_a + parameter_b, [parameter_a, parameter_b])
assert isinstance(model_original, ov.Model)
model_original = Model(parameter_a + parameter_b, [parameter_a, parameter_b])
assert isinstance(model_original, Model)
# Make copies of it
with pytest.deprecated_call():
@ -319,9 +320,9 @@ def test_clone_model():
model_copy2 = model_original.clone()
model_copy3 = deepcopy(model_original)
assert isinstance(model_copy1, ov.Model)
assert isinstance(model_copy2, ov.Model)
assert isinstance(model_copy3, ov.Model)
assert isinstance(model_copy1, Model)
assert isinstance(model_copy2, Model)
assert isinstance(model_copy3, Model)
# Make changes to the copied models' inputs
model_copy1.reshape({"A": [3, 3], "B": [3, 3]})
@ -669,21 +670,21 @@ def test_get_and_set_layout():
model = Model(parameter_a + parameter_b, [parameter_a, parameter_b])
assert layout_helpers.get_layout(model.input(0)) == ov.Layout()
assert layout_helpers.get_layout(model.input(1)) == ov.Layout()
assert layout_helpers.get_layout(model.input(0)) == Layout()
assert layout_helpers.get_layout(model.input(1)) == Layout()
layout_helpers.set_layout(model.input(0), ov.Layout("CH"))
layout_helpers.set_layout(model.input(1), ov.Layout("HW"))
layout_helpers.set_layout(model.input(0), Layout("CH"))
layout_helpers.set_layout(model.input(1), Layout("HW"))
assert layout_helpers.get_layout(model.input(0)) == ov.Layout("CH")
assert layout_helpers.get_layout(model.input(1)) == ov.Layout("HW")
assert layout_helpers.get_layout(model.input(0)) == Layout("CH")
assert layout_helpers.get_layout(model.input(1)) == Layout("HW")
def test_layout():
layout = ov.Layout("NCWH")
layout2 = ov.Layout("NCWH")
scalar = ov.Layout.scalar()
scalar2 = ov.Layout.scalar()
layout = Layout("NCWH")
layout2 = Layout("NCWH")
scalar = Layout.scalar()
scalar2 = Layout.scalar()
assert layout == layout2
assert layout != scalar
@ -708,8 +709,8 @@ def test_layout():
assert layout.get_index_by_name("W") == 2
assert layout.get_index_by_name("H") == 3
layout = ov.Layout("NC?")
layout2 = ov.Layout("N")
layout = Layout("NC?")
layout2 = Layout("N")
assert layout != layout2
assert str(layout) != str(layout2)
assert layout.has_name("N")
@ -720,7 +721,7 @@ def test_layout():
assert layout.get_index_by_name("N") == 0
assert layout.get_index_by_name("C") == 1
layout = ov.Layout("N...C")
layout = Layout("N...C")
assert layout.has_name("N")
assert not (layout.has_name("W"))
assert not (layout.has_name("H"))
@ -728,19 +729,19 @@ def test_layout():
assert layout.has_name("C")
assert layout.get_index_by_name("C") == -1
layout = ov.Layout()
layout = Layout()
assert not (layout.has_name("W"))
assert not (layout.has_name("H"))
assert not (layout.has_name("D"))
assert not (layout.has_name("C"))
layout = ov.Layout("N...C")
layout = Layout("N...C")
assert layout == "N...C"
assert layout != "NC?"
def test_layout_helpers():
layout = ov.Layout("NCHWD")
layout = Layout("NCHWD")
assert (layout_helpers.has_batch(layout))
assert (layout_helpers.has_channels(layout))
assert (layout_helpers.has_depth(layout))
@ -753,7 +754,7 @@ def test_layout_helpers():
assert layout_helpers.width_idx(layout) == 3
assert layout_helpers.depth_idx(layout) == 4
layout = ov.Layout("N...C")
layout = Layout("N...C")
assert (layout_helpers.has_batch(layout))
assert (layout_helpers.has_channels(layout))
assert not (layout_helpers.has_depth(layout))
@ -772,7 +773,7 @@ def test_layout_helpers():
with pytest.raises(RuntimeError):
layout_helpers.depth_idx(layout)
layout = ov.Layout("NC?")
layout = Layout("NC?")
assert (layout_helpers.has_batch(layout))
assert (layout_helpers.has_channels(layout))
assert not (layout_helpers.has_depth(layout))

View File

@ -4,9 +4,8 @@
import numpy as np
import openvino.runtime as ov
import openvino.runtime.opset13 as ops
from openvino.runtime import Type
from openvino import Type
from openvino.runtime.op import Constant
from openvino.helpers import pack_data, unpack_data
@ -39,18 +38,18 @@ class DataGetter(Enum):
@pytest.mark.parametrize(
("dst_dtype"),
[
(ov.Type.f32),
(ov.Type.f64),
(ov.Type.f16),
(ov.Type.i8),
(ov.Type.u8),
(ov.Type.i32),
(ov.Type.u32),
(ov.Type.i16),
(ov.Type.u16),
(ov.Type.i64),
(ov.Type.u64),
(ov.Type.boolean),
(Type.f32),
(Type.f64),
(Type.f16),
(Type.i8),
(Type.u8),
(Type.i32),
(Type.u32),
(Type.i16),
(Type.u16),
(Type.i64),
(Type.u64),
(Type.boolean),
(np.float16),
(np.float32),
(np.float64),
@ -92,7 +91,7 @@ def test_init_with_array(src_dtype, dst_dtype, shared_flag, data_getter):
# Check shape and element type of Constant class
assert isinstance(ov_const, Constant)
assert np.all(tuple(ov_const.shape) == data.shape)
# Additionally check if Constant type matches dst_type if ov.Type was passed:
# Additionally check if Constant type matches dst_type if Type was passed:
if isinstance(dst_dtype, Type):
assert ov_const.get_element_type() == dst_dtype
# Convert to dtype if OpenVINO Type
@ -139,18 +138,18 @@ def test_init_with_array(src_dtype, dst_dtype, shared_flag, data_getter):
@pytest.mark.parametrize(
("dst_dtype"),
[
(ov.Type.f32),
(ov.Type.f64),
(ov.Type.f16),
(ov.Type.i8),
(ov.Type.u8),
(ov.Type.i32),
(ov.Type.u32),
(ov.Type.i16),
(ov.Type.u16),
(ov.Type.i64),
(ov.Type.u64),
(ov.Type.boolean),
(Type.f32),
(Type.f64),
(Type.f16),
(Type.i8),
(Type.u8),
(Type.i32),
(Type.u32),
(Type.i16),
(Type.u16),
(Type.i64),
(Type.u64),
(Type.boolean),
(np.float16),
(np.float32),
(np.float64),
@ -187,7 +186,7 @@ def test_init_with_scalar(init_value, src_dtype, dst_dtype, shared_flag, data_ge
# Check shape and element type of Constant class
assert isinstance(ov_const, Constant)
assert np.all(list(ov_const.shape) == [])
# Additionally check if Constant type matches dst_type if ov.Type was passed:
# Additionally check if Constant type matches dst_type if Type was passed:
if isinstance(dst_dtype, Type):
assert ov_const.get_element_type() == dst_dtype
# Convert to dtype if OpenVINO Type
@ -263,10 +262,10 @@ def test_init_bf16(src_dtype, shared_flag, data_getter):
@pytest.mark.parametrize(
("low", "high", "ov_type", "src_dtype"),
[
(0, 2, ov.Type.u1, np.uint8),
(0, 16, ov.Type.u4, np.uint8),
(-8, 7, ov.Type.i4, np.int8),
(0, 16, ov.Type.nf4, np.uint8),
(0, 2, Type.u1, np.uint8),
(0, 16, Type.u4, np.uint8),
(-8, 7, Type.i4, np.int8),
(0, 16, Type.nf4, np.uint8),
],
)
@pytest.mark.parametrize(

View File

@ -7,10 +7,9 @@ import copy
import numpy as np
import pytest
from openvino import Model, PartialShape, Shape
from openvino import Dimension, Model, PartialShape, Shape
import openvino.runtime.opset8 as ov
from openvino.runtime import Dimension
def test_dimension():

View File

@ -5,7 +5,7 @@
import numpy as np
import pytest
from openvino.runtime import PartialShape, Dimension, Model
from openvino import PartialShape, Dimension, Model, Type
from openvino.runtime.exceptions import UserInputError
from openvino.runtime.utils.types import make_constant_node
@ -13,7 +13,6 @@ import openvino.runtime.opset1 as ov_opset1
import openvino.runtime.opset5 as ov_opset5
import openvino.runtime.opset10 as ov_opset10
import openvino.runtime.opset11 as ov
from openvino.runtime import Type
np_types = [np.float32, np.int32]
integral_np_types = [

View File

@ -5,7 +5,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Type
from openvino import Type
def test_ctc_loss_props():

View File

@ -5,7 +5,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Type, Shape
from openvino import Type, Shape
def test_reverse_sequence():

View File

@ -2,7 +2,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Type
from openvino import Type
import openvino.runtime.opset10 as ov
import numpy as np
import pytest

View File

@ -6,7 +6,7 @@ import numpy as np
import pytest
import openvino.runtime.opset13 as ops
from openvino.runtime import PartialShape, Type
from openvino import PartialShape, Type
@pytest.mark.parametrize(

View File

@ -2,7 +2,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Type
from openvino import Type
import openvino.runtime.opset8 as ov
import numpy as np
import pytest

View File

@ -2,7 +2,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Type
from openvino import Type
import openvino.runtime.opset8 as ov
import numpy as np
import pytest

View File

@ -4,7 +4,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Model
from openvino import Model
from openvino.runtime.op.util import InvariantInputDescription, BodyOutputDescription

View File

@ -4,7 +4,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Shape, Type
from openvino import Shape, Type
def test_log_softmax():

View File

@ -4,7 +4,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Model, Shape
from openvino import Model, Shape
from openvino.runtime.op.util import (
InvariantInputDescription,

View File

@ -9,7 +9,7 @@ import numpy as np
import pytest
import openvino.runtime.opset10 as ops
from openvino.runtime import Core, Model
from openvino import Core, Model
from openvino.runtime.passes import Manager, Serialize, ConstantFolding, Version
from tests.test_graph.util import count_ops_of_type

View File

@ -6,7 +6,7 @@ import numpy as np
import pytest
import openvino.runtime.opset13 as ops
from openvino.runtime import PartialShape, Dimension, Type
from openvino import PartialShape, Type
@pytest.mark.parametrize(

View File

@ -5,12 +5,10 @@
import numpy as np
import pytest
from openvino.runtime import PartialShape, Dimension, Model
from openvino.runtime.exceptions import UserInputError
from openvino.runtime.utils.types import make_constant_node
import openvino.runtime.opset13 as ov_opset13
from openvino.runtime import Type
from openvino import PartialShape, Dimension, Type
from openvino.runtime.utils.types import make_constant_node
@pytest.mark.parametrize(

View File

@ -5,7 +5,7 @@
import numpy as np
import pytest
from sys import platform
from openvino.runtime import compile_model, Model
from openvino import compile_model, Model
import openvino.runtime.opset8 as ov
from openvino.runtime.exceptions import UserInputError
from openvino.runtime.utils.node_factory import NodeFactory

View File

@ -4,7 +4,7 @@
import numpy as np
from openvino.runtime import Type
from openvino import Type
import openvino.runtime.opset13 as ov

View File

@ -8,7 +8,8 @@ import pytest
from contextlib import nullcontext as does_not_raise
import openvino.runtime.opset8 as ov
from openvino.runtime import AxisSet, Shape, Type
from openvino import Shape, Type
from openvino.runtime import AxisSet
from openvino.runtime.op import Constant, Parameter
@pytest.mark.parametrize(("ov_op", "expected_ov_str", "expected_type"), [

View File

@ -7,7 +7,7 @@ import operator
import numpy as np
import pytest
from openvino.runtime import Type
from openvino import Type
import openvino.runtime.opset13 as ov

View File

@ -5,8 +5,8 @@
import numpy as np
import pytest
import openvino.runtime as ov_runtime
import openvino.runtime.opset8 as ov
from openvino import Type
def test_elu_operator_with_scalar_and_array():
@ -131,7 +131,7 @@ def test_squared_difference_operator():
model = ov.squared_difference(parameter_x1, parameter_x2)
assert model.get_type_name() == "SquaredDifference"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 2, 3, 4]
@ -144,7 +144,7 @@ def test_shuffle_channels_operator():
model = ov.shuffle_channels(parameter, axis, groups)
assert model.get_type_name() == "ShuffleChannels"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 15, 2, 2]
@ -156,7 +156,7 @@ def test_unsqueeze():
model = ov.unsqueeze(parameter_data, axes)
assert model.get_type_name() == "Unsqueeze"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 3, 4, 5, 1]
@ -168,7 +168,7 @@ def test_grn_operator():
model = ov.grn(parameter_data, bias)
assert model.get_type_name() == "GRN"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 2, 3, 4]
@ -184,7 +184,7 @@ def test_prelu_operator():
expected = np.clip(data_value, 0, np.inf) + np.clip(data_value, -np.inf, 0) * slope_value
assert model.get_type_name() == "PRelu"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == list(expected.shape)
@ -197,7 +197,7 @@ def test_selu_operator():
model = ov.selu(parameter_data, alpha, lambda_value)
assert model.get_type_name() == "Selu"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [4, 2, 3, 1]
@ -210,7 +210,7 @@ def test_hard_sigmoid_operator():
model = ov.hard_sigmoid(parameter_data, parameter_alpha, parameter_beta)
assert model.get_type_name() == "HardSigmoid"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [3]
@ -225,7 +225,7 @@ def test_mvn_operator():
model = ov.mvn(parameter_data, axes, normalize_variance, eps, eps_mode)
assert model.get_type_name() == "MVN"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [3, 3, 3, 1]
@ -240,7 +240,7 @@ def test_space_to_depth_operator():
model = ov.space_to_depth(parameter_data, mode, block_size)
assert model.get_type_name() == "SpaceToDepth"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 8, 2, 2]
batch_size = 2
@ -278,7 +278,7 @@ def test_space_to_depth_operator():
)
assert model.get_type_name() == "SpaceToDepth"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [batch_size, hidden_size]
@ -297,7 +297,7 @@ def test_group_convolution_operator():
model = ov.group_convolution(parameter_data, parameter_filters, strides, pads_begin, pads_end, dilations)
assert model.get_type_name() == "GroupConvolution"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 2, 2, 2]
@ -317,7 +317,7 @@ def test_group_convolution_backprop_data():
assert model.get_type_name() == "GroupConvolutionBackpropData"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 1, 6, 6]
@ -336,5 +336,5 @@ def test_group_convolution_backprop_data_output_shape():
assert model.get_type_name() == "GroupConvolutionBackpropData"
assert model.get_output_size() == 1
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [1, 1, 1, 14]

View File

@ -2,11 +2,11 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import openvino.runtime as ov_runtime
import openvino.runtime.opset8 as ov
import numpy as np
import pytest
from openvino import Type
from openvino.runtime.utils.types import get_element_type
@ -30,7 +30,7 @@ def test_constant_from_bool(val_type, value, output_shape):
node = ov.constant(value, val_type)
assert node.get_type_name() == "Constant"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.boolean
assert node.get_output_element_type(0) == Type.boolean
assert list(node.get_output_shape(0)) == output_shape
@ -138,7 +138,7 @@ def test_transpose():
node = ov.transpose(input_tensor, input_order)
assert node.get_type_name() == "Transpose"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.i32
assert node.get_output_element_type(0) == Type.i32
assert list(node.get_output_shape(0)) == [3, 224, 224, 3]
@ -149,7 +149,7 @@ def test_tile():
assert node.get_type_name() == "Tile"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.i32
assert node.get_output_element_type(0) == Type.i32
assert list(node.get_output_shape(0)) == [2, 2, 3]
@ -177,7 +177,7 @@ def test_strided_slice():
)
assert node.get_type_name() == "StridedSlice"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [1, 3, 4]
@ -189,7 +189,7 @@ def test_reshape_v1():
node = ov.reshape(param_a, shape, special_zero)
assert node.get_type_name() == "Reshape"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [2, 150, 4]
@ -199,5 +199,5 @@ def test_shape_of():
node = ov.shape_of(input_tensor)
assert node.get_type_name() == "ShapeOf"
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.i64
assert node.get_output_element_type(0) == Type.i64
assert list(node.get_output_shape(0)) == [2]

View File

@ -6,7 +6,7 @@ import numpy as np
import pytest
import openvino.runtime.opset13 as ov
from openvino.runtime import Type
from openvino import Type
def test_scatter_update_props():

View File

@ -5,9 +5,8 @@
import numpy as np
import pytest
import openvino.runtime as ov_runtime
import openvino.runtime.opset13 as ov
from openvino.runtime import Shape, Type
import openvino.runtime.opset13 as ops
from openvino import Shape, Type
R_TOLERANCE = 1e-6 # global relative tolerance
@ -15,28 +14,28 @@ R_TOLERANCE = 1e-6 # global relative tolerance
@pytest.mark.parametrize(
("graph_api_fn", "type_name"),
[
(ov.absolute, "Abs"),
(ov.abs, "Abs"),
(ov.acos, "Acos"),
(ov.acosh, "Acosh"),
(ov.asin, "Asin"),
(ov.asinh, "Asinh"),
(ov.atan, "Atan"),
(ov.atanh, "Atanh"),
(ov.ceiling, "Ceiling"),
(ov.ceil, "Ceiling"),
(ov.cos, "Cos"),
(ov.cosh, "Cosh"),
(ov.exp, "Exp"),
(ov.floor, "Floor"),
(ov.log, "Log"),
(ov.relu, "Relu"),
(ov.sign, "Sign"),
(ov.sin, "Sin"),
(ov.sinh, "Sinh"),
(ov.sqrt, "Sqrt"),
(ov.tan, "Tan"),
(ov.tanh, "Tanh"),
(ops.absolute, "Abs"),
(ops.abs, "Abs"),
(ops.acos, "Acos"),
(ops.acosh, "Acosh"),
(ops.asin, "Asin"),
(ops.asinh, "Asinh"),
(ops.atan, "Atan"),
(ops.atanh, "Atanh"),
(ops.ceiling, "Ceiling"),
(ops.ceil, "Ceiling"),
(ops.cos, "Cos"),
(ops.cosh, "Cosh"),
(ops.exp, "Exp"),
(ops.floor, "Floor"),
(ops.log, "Log"),
(ops.relu, "Relu"),
(ops.sign, "Sign"),
(ops.sin, "Sin"),
(ops.sinh, "Sinh"),
(ops.sqrt, "Sqrt"),
(ops.tan, "Tan"),
(ops.tanh, "Tanh"),
],
)
def test_unary_op_array(graph_api_fn, type_name):
@ -46,36 +45,36 @@ def test_unary_op_array(graph_api_fn, type_name):
node = graph_api_fn(input_data)
assert node.get_output_size() == 1
assert node.get_type_name() == type_name
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [2, 3, 4]
@pytest.mark.parametrize("graph_api_fn", [
ov.absolute,
ov.abs,
ov.acos,
ov.asin,
ov.atan,
ov.ceiling,
ov.ceil,
ov.cos,
ov.cosh,
ov.exp,
ov.floor,
ov.log,
ov.relu,
ov.sign,
ov.sin,
ov.sinh,
ov.sqrt,
ov.tan,
ov.tanh,
ops.absolute,
ops.abs,
ops.acos,
ops.asin,
ops.atan,
ops.ceiling,
ops.ceil,
ops.cos,
ops.cosh,
ops.exp,
ops.floor,
ops.log,
ops.relu,
ops.sign,
ops.sin,
ops.sinh,
ops.sqrt,
ops.tan,
ops.tanh,
])
def test_unary_op_scalar(graph_api_fn):
node = graph_api_fn(np.float32(-0.5))
assert node.get_output_size() == 1
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == []
@ -84,20 +83,20 @@ def test_unary_op_scalar(graph_api_fn):
[(np.array([True, False, True, False])), (np.array([True])), (np.array([False]))],
)
def test_logical_not(input_data):
node = ov.logical_not(input_data)
node = ops.logical_not(input_data)
assert node.get_output_size() == 1
assert node.get_type_name() == "LogicalNot"
assert node.get_output_element_type(0) == ov_runtime.Type.boolean
assert node.get_output_element_type(0) == Type.boolean
assert list(node.get_output_shape(0)) == list(input_data.shape)
def test_sigmoid():
input_data = np.array([-3.14, -1.0, 0.0, 2.71001, 1000.0], dtype=np.float32)
node = ov.sigmoid(input_data)
node = ops.sigmoid(input_data)
assert node.get_output_size() == 1
assert node.get_type_name() == "Sigmoid"
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [5]
@ -105,28 +104,28 @@ def test_softmax():
axis = 1
input_tensor = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
node = ov.softmax(input_tensor, axis)
node = ops.softmax(input_tensor, axis)
assert node.get_output_size() == 1
assert node.get_type_name() == "Softmax"
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [2, 3]
def test_erf():
input_tensor = np.array([-1.0, 0.0, 1.0, 2.5, 3.14, 4.0], dtype=np.float32)
node = ov.erf(input_tensor)
node = ops.erf(input_tensor)
assert node.get_output_size() == 1
assert node.get_type_name() == "Erf"
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [6]
def test_hswish():
float_dtype = np.float32
data = ov.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
data = ops.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
node = ov.hswish(data)
node = ops.hswish(data)
assert node.get_type_name() == "HSwish"
assert node.get_output_size() == 1
assert list(node.get_output_shape(0)) == [3, 10]
@ -135,9 +134,9 @@ def test_hswish():
def test_round():
float_dtype = np.float32
data = ov.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
data = ops.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
node = ov.round(data, "HALF_TO_EVEN")
node = ops.round(data, "HALF_TO_EVEN")
assert node.get_type_name() == "Round"
assert node.get_output_size() == 1
assert list(node.get_output_shape(0)) == [3, 10]
@ -145,18 +144,18 @@ def test_round():
input_tensor = np.array([-2.5, -1.5, -0.5, 0.5, 0.9, 1.5, 2.3, 2.5, 3.5], dtype=np.float32)
node = ov.round(input_tensor, "HALF_TO_EVEN")
node = ops.round(input_tensor, "HALF_TO_EVEN")
assert node.get_output_size() == 1
assert node.get_type_name() == "Round"
assert node.get_output_element_type(0) == ov_runtime.Type.f32
assert node.get_output_element_type(0) == Type.f32
assert list(node.get_output_shape(0)) == [9]
def test_hsigmoid():
float_dtype = np.float32
data = ov.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
data = ops.parameter(Shape([3, 10]), dtype=float_dtype, name="data")
node = ov.hsigmoid(data)
node = ops.hsigmoid(data)
assert node.get_type_name() == "HSigmoid"
assert node.get_output_size() == 1
assert list(node.get_output_shape(0)) == [3, 10]
@ -165,58 +164,58 @@ def test_hsigmoid():
def test_gelu_operator_with_parameters():
data_shape = [2, 2]
parameter_data = ov.parameter(data_shape, name="Data", dtype=np.float32)
parameter_data = ops.parameter(data_shape, name="Data", dtype=np.float32)
model = ov.gelu(parameter_data, "erf")
model = ops.gelu(parameter_data, "erf")
assert model.get_output_size() == 1
assert model.get_type_name() == "Gelu"
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [2, 2]
def test_gelu_operator_with_array():
data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32)
model = ov.gelu(data_value, "erf")
model = ops.gelu(data_value, "erf")
assert model.get_output_size() == 1
assert model.get_type_name() == "Gelu"
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [2, 2]
def test_gelu_tanh_operator_with_parameters():
data_shape = [2, 2]
parameter_data = ov.parameter(data_shape, name="Data", dtype=np.float32)
parameter_data = ops.parameter(data_shape, name="Data", dtype=np.float32)
model = ov.gelu(parameter_data, "tanh")
model = ops.gelu(parameter_data, "tanh")
assert model.get_output_size() == 1
assert model.get_type_name() == "Gelu"
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [2, 2]
def test_gelu_tanh_operator_with_array():
data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32)
model = ov.gelu(data_value, "tanh")
model = ops.gelu(data_value, "tanh")
assert model.get_output_size() == 1
assert model.get_type_name() == "Gelu"
assert model.get_output_element_type(0) == ov_runtime.Type.f32
assert model.get_output_element_type(0) == Type.f32
assert list(model.get_output_shape(0)) == [2, 2]
@pytest.mark.parametrize(
("input_data", "dtype"),
[
(np.array([True, False, True, False]), ov_runtime.Type.boolean),
(np.array([True]), ov_runtime.Type.boolean),
(np.array([False]), ov_runtime.Type.boolean),
(np.array([0, 3, 7, 256], dtype=np.uint16), ov_runtime.Type.u16),
(np.array([[-7, 0], [256, 1]], dtype=np.int32), ov_runtime.Type.i32),
(np.array([True, False, True, False]), Type.boolean),
(np.array([True]), Type.boolean),
(np.array([False]), Type.boolean),
(np.array([0, 3, 7, 256], dtype=np.uint16), Type.u16),
(np.array([[-7, 0], [256, 1]], dtype=np.int32), Type.i32),
],
)
def test_bitwise_not(input_data, dtype):
node = ov.bitwise_not(input_data)
node = ops.bitwise_not(input_data)
assert node.get_output_size() == 1
assert node.get_type_name() == "BitwiseNot"
assert node.get_output_element_type(0) == dtype

View File

@ -2,7 +2,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import PartialShape, Type
from openvino import PartialShape, Type
from openvino.runtime.op.util import VariableInfo, Variable

View File

@ -7,7 +7,7 @@ import numpy as np
import pytest
import openvino.runtime.opset13 as ov
from openvino.runtime import Type
from openvino import Type
@pytest.mark.parametrize(

View File

@ -6,7 +6,7 @@ import numpy as np
import pytest
import openvino.runtime.opset8 as ov
from openvino.runtime import Type
from openvino import Type
@pytest.fixture()

View File

@ -5,11 +5,11 @@
import numpy as np
import pytest
import openvino.runtime as ov
import openvino.runtime.opset8 as ops
from openvino.runtime import Model, Output, Type
import openvino.runtime.opset13 as ops
from openvino import Core, Layout, Model, Shape, Tensor, Type
from openvino.runtime.utils.decorators import custom_preprocess_function
from openvino.runtime import Core
from openvino.runtime import Output
from openvino.preprocess import PrePostProcessor, ColorFormat, ResizeAlgorithm
@ -37,7 +37,7 @@ def test_graph_preprocess_mean_vector():
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout = ov.Layout("NC")
layout = Layout("NC")
ppp = PrePostProcessor(function)
ppp.input().tensor().set_layout(layout)
@ -58,7 +58,7 @@ def test_graph_preprocess_scale_vector():
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout = ov.Layout("NC")
layout = Layout("NC")
ppp = PrePostProcessor(function)
inp = ppp.input()
@ -161,8 +161,8 @@ def test_graph_preprocess_output_postprocess():
parameter_a = ops.parameter(shape, dtype=np.int32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout1 = ov.Layout("NC")
layout2 = ov.Layout("CN")
layout1 = Layout("NC")
layout2 = Layout("CN")
layout3 = [1, 0]
@custom_preprocess_function
@ -203,7 +203,7 @@ def test_graph_preprocess_spatial_static_shape():
parameter_a = ops.parameter(shape, dtype=np.int32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout = ov.Layout("CHW")
layout = Layout("CHW")
color_format = ColorFormat.RGB
@ -272,19 +272,19 @@ def test_graph_preprocess_set_from_tensor():
shape = [1, 224, 224, 3]
inp_shape = [1, 480, 640, 3]
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
parameter_a.set_layout(ov.Layout("NHWC"))
parameter_a.set_layout(Layout("NHWC"))
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
input_data = ov.Tensor(Type.i32, inp_shape)
input_data = Tensor(Type.i32, inp_shape)
ppp = PrePostProcessor(function)
inp = ppp.input()
inp.tensor().set_from(input_data)
inp.preprocess().resize(ResizeAlgorithm.RESIZE_LINEAR)
function = ppp.build()
assert function.input().shape == ov.Shape(inp_shape)
assert function.input().shape == Shape(inp_shape)
assert function.input().element_type == Type.i32
assert function.output().shape == ov.Shape(shape)
assert function.output().shape == Shape(shape)
assert function.output().element_type == Type.f32
@ -311,7 +311,7 @@ def test_graph_preprocess_set_from_np_infer():
inp.tensor().set_from(input_data)
inp.preprocess().convert_element_type().custom(custom_crop)
function = ppp.build()
assert function.input().shape == ov.Shape([3, 3, 3])
assert function.input().shape == Shape([3, 3, 3])
assert function.input().element_type == Type.i32
model_operators = [op.get_name().split("_")[0] for op in function.get_ops()]
@ -381,8 +381,8 @@ def test_graph_preprocess_steps(algorithm, color_format1, color_format2, is_fail
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout1 = ov.Layout("NCWH")
layout2 = ov.Layout("NCHW")
layout1 = Layout("NCWH")
layout2 = Layout("NCHW")
custom_processor = PrePostProcessor(function)
inp = custom_processor.input()
@ -439,8 +439,8 @@ def test_graph_preprocess_postprocess_layout():
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout1 = ov.Layout("NCWH")
layout2 = ov.Layout("NCHW")
layout1 = Layout("NCWH")
layout2 = Layout("NCHW")
ppp = PrePostProcessor(function)
inp = ppp.input()
@ -472,7 +472,7 @@ def test_graph_preprocess_reverse_channels():
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
layout1 = ov.Layout("NCWH")
layout1 = Layout("NCWH")
ppp = PrePostProcessor(function)
inp = ppp.input()
@ -530,7 +530,7 @@ def test_graph_preprocess_resize_algorithm():
model = parameter_a
function = Model(model, [parameter_a], "TestFunction")
resize_alg = ResizeAlgorithm.RESIZE_CUBIC
layout1 = ov.Layout("NCWH")
layout1 = Layout("NCWH")
ppp = PrePostProcessor(function)
inp = ppp.input()
@ -653,12 +653,12 @@ def test_graph_preprocess_dump():
function = Model(model, [parameter_a], "TestFunction")
ppp = PrePostProcessor(function)
ppp.input().tensor().set_layout(ov.Layout("NHWC")).set_element_type(Type.u8)
ppp.input().tensor().set_layout(Layout("NHWC")).set_element_type(Type.u8)
ppp.input().tensor().set_spatial_dynamic_shape()
ppp.input().preprocess().convert_element_type(Type.f32).reverse_channels()
ppp.input().preprocess().mean([1, 2, 3]).scale([4, 5, 6])
ppp.input().preprocess().resize(ResizeAlgorithm.RESIZE_LINEAR)
ppp.input().model().set_layout(ov.Layout("NCHW"))
ppp.input().model().set_layout(Layout("NCHW"))
p_str = str(ppp)
assert "Pre-processing steps (5):" in p_str
assert "convert type (f32):" in p_str
@ -667,7 +667,7 @@ def test_graph_preprocess_dump():
assert "scale (4,5,6):" in p_str
assert "resize to model width/height:" in p_str
assert "Implicit pre-processing steps (1):" in p_str
assert "convert layout " + ov.Layout("NCHW").to_string() in p_str
assert "convert layout " + Layout("NCHW").to_string() in p_str
@pytest.mark.parametrize(
@ -687,7 +687,7 @@ def test_ngraph_set_layout_by_string(layout, layout_str):
@pytest.mark.parametrize(
("layout", "layout_str"),
[(ov.Layout("NHCW"), "[N,H,C,W]"), (ov.Layout("NHWC"), "[N,H,W,C]")])
[(Layout("NHCW"), "[N,H,C,W]"), (Layout("NHWC"), "[N,H,W,C]")])
def test_ngraph_set_layout_by_layout_class(layout, layout_str):
shape = [1, 3, 224, 224]
parameter_a = ops.parameter(shape, dtype=np.float32, name="RGB_input")
@ -725,6 +725,6 @@ def test_ngraph_set_layout_by_layout_class_thow_exception():
ppp = PrePostProcessor(function)
with pytest.raises(RuntimeError) as e:
layout = ov.Layout("1-2-3D")
layout = Layout("1-2-3D")
ppp.input().model().set_layout(layout)
assert "Layout name is invalid" in str(e.value)

View File

@ -4,7 +4,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Shape, Type
from openvino import Shape, Type
def test_proposal_props():

View File

@ -2,9 +2,9 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import openvino.runtime as ov
import openvino.runtime.opset8 as ops
import numpy as np
import openvino.runtime.opset8 as ops
from openvino import Type
def test_random_uniform():
@ -17,5 +17,5 @@ def test_random_uniform():
op_seed=1546)
assert random_uniform_node.get_output_size() == 1
assert random_uniform_node.get_type_name() == "RandomUniform"
assert random_uniform_node.get_output_element_type(0) == ov.Type.f32
assert random_uniform_node.get_output_element_type(0) == Type.f32
assert list(random_uniform_node.get_output_shape(0)) == [2, 4, 3]

View File

@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
import openvino.runtime.opset10 as ov
from openvino.runtime import Shape, Type
from openvino import Shape, Type
import numpy as np
import pytest

View File

@ -5,7 +5,7 @@
import numpy as np
import pytest
import openvino.runtime.opset8 as ov
from openvino.runtime import Shape, Type
from openvino import Shape, Type
@pytest.mark.parametrize(("beta"), [

View File

@ -4,7 +4,7 @@
import numpy as np
import openvino.runtime.opset8 as ov
from openvino.runtime import Model, Shape
from openvino import Model, Shape
from openvino.runtime.op.util import (
InvariantInputDescription,

View File

@ -5,7 +5,7 @@
import openvino.runtime as ov
import pytest
from openvino._pyopenvino.util import deprecation_warning
from openvino.runtime import Shape
from openvino import Shape
def test_get_constant_from_source_success():

View File

@ -4,7 +4,7 @@
import numpy as np
from openvino.runtime import Tensor, Type
from openvino import Tensor, Type
def test_run():

View File

@ -676,7 +676,7 @@ def test_infer_queue_get_idle_handle(device):
def test_query_state_write_buffer(device, input_shape, data_type, mode):
core = Core()
from openvino.runtime import Tensor
from openvino import Tensor
from openvino.runtime.utils.types import get_dtype
model = create_model_with_memory(input_shape, data_type)

View File

@ -5,8 +5,7 @@
import numpy as np
import pytest
import openvino.runtime as ov
from openvino import Tensor
from openvino import Tensor, Type
from openvino.runtime.op import Constant
from tests.utils.helpers import generate_image
@ -28,18 +27,18 @@ def test_init_with_numpy_fail(cls, cls_str):
@pytest.mark.parametrize("cls", [Tensor, Constant])
@pytest.mark.parametrize("shared_flag", [True, False])
@pytest.mark.parametrize(("ov_type", "numpy_dtype"), [
(ov.Type.f32, np.float32),
(ov.Type.f64, np.float64),
(ov.Type.f16, np.float16),
(ov.Type.i8, np.int8),
(ov.Type.u8, np.uint8),
(ov.Type.i32, np.int32),
(ov.Type.u32, np.uint32),
(ov.Type.i16, np.int16),
(ov.Type.u16, np.uint16),
(ov.Type.i64, np.int64),
(ov.Type.u64, np.uint64),
(ov.Type.boolean, bool),
(Type.f32, np.float32),
(Type.f64, np.float64),
(Type.f16, np.float16),
(Type.i8, np.int8),
(Type.u8, np.uint8),
(Type.i32, np.int32),
(Type.u32, np.uint32),
(Type.i16, np.int16),
(Type.u16, np.uint16),
(Type.i64, np.int64),
(Type.u64, np.uint64),
(Type.boolean, bool),
])
def test_with_numpy_memory(cls, shared_flag, ov_type, numpy_dtype):
arr = np.ascontiguousarray(generate_image().astype(numpy_dtype))
@ -95,18 +94,18 @@ def test_with_external_memory(cls, shared_flag):
@pytest.mark.parametrize("shared_flag_one", [True, False])
@pytest.mark.parametrize("shared_flag_two", [True, False])
@pytest.mark.parametrize(("ov_type", "numpy_dtype"), [
(ov.Type.f32, np.float32),
(ov.Type.f64, np.float64),
(ov.Type.f16, np.float16),
(ov.Type.i8, np.int8),
(ov.Type.u8, np.uint8),
(ov.Type.i32, np.int32),
(ov.Type.u32, np.uint32),
(ov.Type.i16, np.int16),
(ov.Type.u16, np.uint16),
(ov.Type.i64, np.int64),
(ov.Type.u64, np.uint64),
(ov.Type.boolean, bool),
(Type.f32, np.float32),
(Type.f64, np.float64),
(Type.f16, np.float16),
(Type.i8, np.int8),
(Type.u8, np.uint8),
(Type.i32, np.int32),
(Type.u32, np.uint32),
(Type.i16, np.int16),
(Type.u16, np.uint16),
(Type.i64, np.int64),
(Type.u64, np.uint64),
(Type.boolean, bool),
])
def test_with_tensor_memory(cls, shared_flag_one, shared_flag_two, ov_type, numpy_dtype):
arr = np.ascontiguousarray(generate_image().astype(numpy_dtype))

View File

@ -9,7 +9,8 @@ import io
import threading
import numpy as np
from openvino.runtime import Core, Model, AsyncInferQueue, PartialShape, Layout, opset13 as ops, serialize
from openvino import Core, Model, AsyncInferQueue, PartialShape, Layout, serialize
from openvino.runtime import opset13 as ops
from openvino.preprocess import PrePostProcessor
from tests import skip_devtest

View File

@ -9,7 +9,7 @@ import sys
import numpy as np
import openvino as ov
import openvino.runtime.opset11 as ops
import openvino.runtime.opset13 as ops
from openvino.helpers import pack_data, unpack_data
import pytest

View File

@ -12,8 +12,7 @@ import torch
import torch.nn.functional as f
import torchvision.transforms as transforms
from openvino import Type
from openvino.runtime import Core, Tensor
from openvino import Type, Core
from openvino.tools.mo import convert_model
from openvino.properties.hint import inference_precision

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import opset8
from openvino.runtime.passes import Manager, GraphRewrite, MatcherPass, WrapType, Matcher

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime.passes import Manager, GraphRewrite, BackwardGraphRewrite, Serialize

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import opset8
from openvino.runtime.passes import Manager, Matcher, MatcherPass, WrapType

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime.passes import Manager

View File

@ -16,7 +16,7 @@ from openvino._offline_transformations import (
apply_fused_names_cleanup,
)
from openvino.runtime import Model, PartialShape, Core, serialize, save_model
from openvino import Model, PartialShape, Core, serialize, save_model
import openvino.runtime as ov
from tests.utils.helpers import create_filename_for_test, compare_models, _compare_models

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
from openvino.runtime import PartialShape, opset8
from openvino import PartialShape
from openvino.runtime import opset13 as ops
from openvino.runtime.passes import Matcher, WrapType, Or, AnyInput
from openvino.runtime.passes import (
consumers_count,
@ -31,53 +32,53 @@ def test_wrap_type_pattern_type():
# Generic negative test cases
expect_exception(lambda: WrapType(""))
expect_exception(lambda: WrapType("opset8"))
expect_exception(lambda: WrapType("ops"))
expect_exception(lambda: WrapType("Parameter"))
expect_exception(lambda: WrapType("opset.Parameter"))
expect_exception(lambda: WrapType("opset8,Parameter"))
expect_exception(lambda: WrapType("Parameter.opset8"))
expect_exception(lambda: WrapType("ops,Parameter"))
expect_exception(lambda: WrapType("Parameter.ops"))
def test_wrap_type_ctors():
param = opset8.parameter(PartialShape([1, 3, 22, 22]))
relu = opset8.relu(param.output(0))
slope = opset8.parameter(PartialShape([]))
prelu = opset8.prelu(param.output(0), slope.output(0))
param = ops.parameter(PartialShape([1, 3, 22, 22]))
relu = ops.relu(param.output(0))
slope = ops.parameter(PartialShape([]))
prelu = ops.prelu(param.output(0), slope.output(0))
matcher = Matcher(WrapType(["opset8.Relu", "opset8.PRelu"]), "FindActivation")
matcher = Matcher(WrapType(["opset13.Relu", "opset13.PRelu"]), "FindActivation")
assert matcher.match(relu)
assert matcher.match(prelu)
matcher = Matcher(WrapType(["opset8.Relu", "opset8.PRelu"],
WrapType("opset8.Parameter").output(0)), "FindActivation")
matcher = Matcher(WrapType(["opset13.Relu", "opset13.PRelu"],
WrapType("opset13.Parameter").output(0)), "FindActivation")
assert matcher.match(relu)
def test_or():
param = opset8.parameter(PartialShape([1, 3, 22, 22]))
relu = opset8.relu(param.output(0))
slope = opset8.parameter(PartialShape([]))
prelu = opset8.prelu(param.output(0), slope.output(0))
param = ops.parameter(PartialShape([1, 3, 22, 22]))
relu = ops.relu(param.output(0))
slope = ops.parameter(PartialShape([]))
prelu = ops.prelu(param.output(0), slope.output(0))
matcher = Matcher(Or([WrapType("opset8.Relu"), WrapType("opset8.PRelu")]), "FindActivation")
matcher = Matcher(Or([WrapType("opset13.Relu"), WrapType("opset13.PRelu")]), "FindActivation")
assert matcher.match(relu)
assert matcher.match(prelu)
def test_any_input():
param = opset8.parameter(PartialShape([1, 3, 22, 22]))
relu = opset8.relu(param.output(0))
slope = opset8.parameter(PartialShape([]))
prelu = opset8.prelu(param.output(0), slope.output(0))
param = ops.parameter(PartialShape([1, 3, 22, 22]))
relu = ops.relu(param.output(0))
slope = ops.parameter(PartialShape([]))
prelu = ops.prelu(param.output(0), slope.output(0))
matcher = Matcher(WrapType("opset8.PRelu", [AnyInput(), AnyInput()]), "FindActivation")
matcher = Matcher(WrapType("opset13.PRelu", [AnyInput(), AnyInput()]), "FindActivation")
assert not matcher.match(relu)
assert matcher.match(prelu)
def test_any_input_predicate():
param = opset8.parameter(PartialShape([1, 3, 22, 22]))
slope = opset8.parameter(PartialShape([]))
param = ops.parameter(PartialShape([1, 3, 22, 22]))
slope = ops.parameter(PartialShape([]))
matcher = Matcher(AnyInput(lambda output: len(output.get_shape()) == 4), "FindActivation")
assert matcher.match(param)
@ -85,33 +86,33 @@ def test_any_input_predicate():
def test_all_predicates():
static_param = opset8.parameter(PartialShape([1, 3, 22, 22]), np.float32)
dynamic_param = opset8.parameter(PartialShape([-1, 6]), np.compat.long)
fully_dynamic_param = opset8.parameter(PartialShape.dynamic())
static_param = ops.parameter(PartialShape([1, 3, 22, 22]), np.float32)
dynamic_param = ops.parameter(PartialShape([-1, 6]), np.compat.long)
fully_dynamic_param = ops.parameter(PartialShape.dynamic())
assert Matcher(WrapType("opset8.Parameter", consumers_count(0)), "Test").match(static_param)
assert not Matcher(WrapType("opset8.Parameter", consumers_count(1)), "Test").match(static_param)
assert Matcher(WrapType("opset13.Parameter", consumers_count(0)), "Test").match(static_param)
assert not Matcher(WrapType("opset13.Parameter", consumers_count(1)), "Test").match(static_param)
assert Matcher(WrapType("opset8.Parameter", has_static_dim(1)), "Test").match(static_param)
assert not Matcher(WrapType("opset8.Parameter", has_static_dim(0)), "Test").match(dynamic_param)
assert Matcher(WrapType("opset13.Parameter", has_static_dim(1)), "Test").match(static_param)
assert not Matcher(WrapType("opset13.Parameter", has_static_dim(0)), "Test").match(dynamic_param)
assert Matcher(WrapType("opset8.Parameter", has_static_dims([0, 3])), "Test").match(static_param)
assert not Matcher(WrapType("opset8.Parameter", has_static_dims([0, 1])), "Test").match(dynamic_param)
assert Matcher(WrapType("opset13.Parameter", has_static_dims([0, 3])), "Test").match(static_param)
assert not Matcher(WrapType("opset13.Parameter", has_static_dims([0, 1])), "Test").match(dynamic_param)
assert Matcher(WrapType("opset8.Parameter", has_static_shape()), "Test").match(static_param)
assert not Matcher(WrapType("opset8.Parameter", has_static_shape()), "Test").match(dynamic_param)
assert Matcher(WrapType("opset13.Parameter", has_static_shape()), "Test").match(static_param)
assert not Matcher(WrapType("opset13.Parameter", has_static_shape()), "Test").match(dynamic_param)
assert Matcher(WrapType("opset8.Parameter", has_static_rank()), "Test").match(dynamic_param)
assert not Matcher(WrapType("opset8.Parameter", has_static_rank()), "Test").match(fully_dynamic_param)
assert Matcher(WrapType("opset13.Parameter", has_static_rank()), "Test").match(dynamic_param)
assert not Matcher(WrapType("opset13.Parameter", has_static_rank()), "Test").match(fully_dynamic_param)
assert Matcher(WrapType("opset8.Parameter",
assert Matcher(WrapType("opset13.Parameter",
type_matches(get_element_type(np.float32))), "Test").match(static_param)
assert not Matcher(WrapType("opset8.Parameter",
assert not Matcher(WrapType("opset13.Parameter",
type_matches(get_element_type(np.float32))), "Test").match(dynamic_param)
assert Matcher(WrapType("opset8.Parameter", # noqa: ECE001
assert Matcher(WrapType("opset13.Parameter", # noqa: ECE001
type_matches_any([get_element_type(np.float32),
get_element_type(np.compat.long)])), "Test").match(static_param)
assert Matcher(WrapType("opset8.Parameter", # noqa: ECE001
assert Matcher(WrapType("opset13.Parameter", # noqa: ECE001
type_matches_any([get_element_type(np.float32),
get_element_type(np.compat.long)])), "Test").match(dynamic_param)

View File

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import numpy as np
from openvino.runtime import Model, PartialShape, Shape, Core
from openvino.runtime import opset10
from openvino import Model, PartialShape, Shape, Core
from openvino.runtime import opset13 as ops
from openvino.runtime.passes import (
Manager,
ConstantFolding,
@ -21,21 +21,21 @@ from tests.utils.helpers import create_filename_for_test, compare_models
def get_model():
param = opset10.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
param.get_output_tensor(0).set_names({"parameter"})
relu = opset10.relu(param)
reshape = opset10.reshape(relu, opset10.shape_of(relu), False)
res = opset10.result(reshape, name="result")
relu = ops.relu(param)
reshape = ops.reshape(relu, ops.shape_of(relu), False)
res = ops.result(reshape, name="result")
res.get_output_tensor(0).set_names({"result"})
return Model([res], [param], "test")
def test_make_stateful():
param = opset10.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
param.get_output_tensor(0).set_names({"parameter"})
relu = opset10.relu(param)
reshape = opset10.reshape(relu, opset10.shape_of(relu), False)
res = opset10.result(reshape, name="result")
relu = ops.relu(param)
reshape = ops.reshape(relu, ops.shape_of(relu), False)
res = ops.result(reshape, name="result")
res.get_output_tensor(0).set_names({"result"})
model = Model([res], [param], "test")
@ -87,20 +87,20 @@ def test_convert_precision():
def test_low_latency2():
param_x = opset10.parameter(Shape([32, 40, 10]), np.float32, "X")
param_y = opset10.parameter(Shape([32, 40, 10]), np.float32, "Y")
param_m = opset10.parameter(Shape([32, 2, 10]), np.float32, "M")
param_x = ops.parameter(Shape([32, 40, 10]), np.float32, "X")
param_y = ops.parameter(Shape([32, 40, 10]), np.float32, "Y")
param_m = ops.parameter(Shape([32, 2, 10]), np.float32, "M")
x_i = opset10.parameter(Shape([32, 2, 10]), np.float32, "X_i")
y_i = opset10.parameter(Shape([32, 2, 10]), np.float32, "Y_i")
m_body = opset10.parameter(Shape([32, 2, 10]), np.float32, "M_body")
x_i = ops.parameter(Shape([32, 2, 10]), np.float32, "X_i")
y_i = ops.parameter(Shape([32, 2, 10]), np.float32, "Y_i")
m_body = ops.parameter(Shape([32, 2, 10]), np.float32, "M_body")
add = opset10.add(x_i, y_i)
zo = opset10.multiply(add, m_body)
add = ops.add(x_i, y_i)
zo = ops.multiply(add, m_body)
body = Model([zo], [x_i, y_i, m_body], "body_function")
ti = opset10.tensor_iterator()
ti = ops.tensor_iterator()
ti.set_body(body)
ti.set_sliced_input(x_i, param_x.output(0), 0, 2, 2, 39, 1)
ti.set_sliced_input(y_i, param_y.output(0), 0, 2, 2, -1, 1)
@ -109,8 +109,8 @@ def test_low_latency2():
out0 = ti.get_iter_value(zo.output(0), -1)
out1 = ti.get_concatenated_slices(zo.output(0), 0, 2, 2, 39, 1)
result0 = opset10.result(out0)
result1 = opset10.result(out1)
result0 = ops.result(out0)
result1 = ops.result(out1)
model = Model([result0, result1], [param_x, param_y, param_m])

View File

@ -1,36 +1,37 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Model, PartialShape, opset8
from openvino import Model, PartialShape
from openvino.runtime import opset13 as ops
from openvino.runtime.utils import replace_node, replace_output_update_name
def get_relu_model():
# Parameter->Relu->Result
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
res = opset8.result(relu.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
res = ops.result(relu.output(0), name="result")
return Model([res], [param], "test")
def test_output_replace():
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
res = opset8.result(relu.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
res = ops.result(relu.output(0), name="result")
exp = opset8.exp(param.output(0))
exp = ops.exp(param.output(0))
relu.output(0).replace(exp.output(0))
assert res.input_value(0).get_node() == exp
def test_replace_source_output():
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
res = opset8.result(relu.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
res = ops.result(relu.output(0), name="result")
exp = opset8.exp(param.output(0))
exp = ops.exp(param.output(0))
res.input(0).replace_source_output(exp.output(0))
assert len(exp.output(0).get_target_inputs()) == 1
@ -40,21 +41,21 @@ def test_replace_source_output():
def test_replace_node():
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
res = opset8.result(relu.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
res = ops.result(relu.output(0), name="result")
exp = opset8.exp(param.output(0))
exp = ops.exp(param.output(0))
replace_node(relu, exp)
assert res.input_value(0).get_node() == exp
def test_replace_output_update_name():
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
exp = opset8.exp(relu.output(0))
res = opset8.result(exp.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
exp = ops.exp(relu.output(0))
res = ops.result(exp.output(0), name="result")
replace_output_update_name(exp.output(0), exp.input_value(0))

View File

@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Model, PartialShape, opset8
from openvino import Model, PartialShape
from openvino.runtime import opset13 as ops
from openvino.runtime.passes import ModelPass, Matcher, MatcherPass, WrapType
def get_relu_model():
# Parameter->Relu->Result
param = opset8.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = opset8.relu(param.output(0))
res = opset8.result(relu.output(0), name="result")
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
res = ops.result(relu.output(0), name="result")
return Model([res], [param], "test")
@ -45,12 +46,12 @@ class PatternReplacement(MatcherPass):
MatcherPass.__init__(self)
self.model_changed = False
relu = WrapType("opset8::Relu")
relu = WrapType("opset13::Relu")
def callback(matcher: Matcher) -> bool:
self.applied = True
root = matcher.get_match_root()
new_relu = opset8.relu(root.input(0).get_source_output())
new_relu = ops.relu(root.input(0).get_source_output())
# For testing purpose
self.model_changed = True

View File

@ -7,7 +7,8 @@ import pytest
import numpy as np
from tests.utils.helpers import generate_relu_compiled_model
from openvino.runtime import Model, ConstOutput, Type, Shape, Core, Tensor
from openvino import Model, Type, Shape, Core, Tensor
from openvino.runtime import ConstOutput
from openvino.runtime.utils.data_helpers import _data_dispatch
is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD"

View File

@ -12,8 +12,8 @@ from sys import platform
from pathlib import Path
import openvino
from openvino import Model, Core, Shape
import openvino.runtime.opset13 as ops
from openvino.runtime import Model, Core, Shape
def _compare_models(model_one: Model, model_two: Model, compare_names: bool = True) -> Tuple[bool, str]: # noqa: C901 the function is too complex
@ -172,7 +172,7 @@ def get_model_with_template_extension():
return core, core.read_model(ir)
def get_relu_model(input_shape: List[int] = None, input_dtype=np.float32) -> openvino.runtime.Model:
def get_relu_model(input_shape: List[int] = None, input_dtype=np.float32) -> openvino.Model:
if input_shape is None:
input_shape = [1, 3, 32, 32]
param = ops.parameter(input_shape, input_dtype, name="data")
@ -188,7 +188,7 @@ def generate_relu_compiled_model(
device,
input_shape: List[int] = None,
input_dtype=np.float32,
) -> openvino.runtime.CompiledModel:
) -> openvino.CompiledModel:
if input_shape is None:
input_shape = [1, 3, 32, 32]
model = get_relu_model(input_shape, input_dtype)