Remove test-generator dependency (#18512)

* changed from generator to unittest

* common_test.py tested for pylint 7.96/10

* ChangeRandomUniformOutputType_test pylint 10/10

* replaced  generator functionality from compress...

* replaced generator functionality in MatMulNormal..

* replaced generator functionality in ShuffleChan...

* replaced generator functionality in import_from_mo_test.py

* replaced generator functionality in meta_data_test.py

* replaced generator functionality in extractor_test.py

* replaced generator functionality in interpolate_reshape_test.py

* replaced generator functionality in Pack_test.py

* replaced generator functionality in rank_decomposer_test.py

* replaced generator functionality in size_replacer_test.py

* replaced generator functionality in utils_test.py

* replaced generator functionality in eltwise_test.py

* replaced generator functionality in concat_test.py

* replaced generator functionality in tdnn_component_replacer_test.py

* replaced generator functionality in MXFFTToDFT_test.py

* replaced generator functionality in activation_ext_test.py

* replaced generator functionality in AttributedSliceToSlice_test

* replaced generator functionality in squeeze_ext_test.py

* replaced generator functionality in transpose_ext_test.py

* replaced generator functionality in unsqueeze_ext_test.py

* replaced generator functionality in ObjectDetectionAPI_test.py

* replaced generator functionality in  RFFTRealImagToRFFTSplit_test.py

* replaced generator functionality in TFFFTToDFT_test.py

* replaced generator functionality in WhereDecomposition_test.py

* replaced generator functionality in graph_test.py

* replaced generator functionality in ConvertGroupedStridedSlice_test.py

* replaced generator functionality in dequantize_linear_resolver_test.py

* replaced generator functionality in FusedBatchNormTraining_test.py

* replaced generator functionality in L2NormFusing_test.py

* replaced generator functionality in PreserveRuntimeInfo_test.py

* replaced generator functionality in quantize_linear_resolver_test.py

* replaced generator functionality in UpsampleToResample_test.py

* replaced generator functionality in broadcast_test.py

* replaced generator functionality in loader_test.py

* replaced generator functionality in cast_test.py

* replaced generator functionality in Complex_test.py

* replaced generator functionality in dft_signal_size_canonicalization_test.py

* replaced generator functionality in div_value_propagation_test.py

* replaced generator functionality in einsum_test.py

* replaced generator functionality in expand_dims_test.py

* replaced generator functionality in ExtractImagePatches_test.py

* replaced generator functionality in eye_test.py

* replaced generator functionality in gatherelements_test.py

* replaced generator functionality in If_test.py

* replaced generator functionality in interpolate_test.py

* replaced generator functionality in MatMul_test.py

* replaced generator functionality in MatMul_value_propagation_test.py

* replaced generator functionality in one_hot_test.py

* replaced generator functionality in ONNXResize11_test.py

* replaced generator functionality in ReduceOps_test.py

* replaced generator functionality in reshape_test.py

* replaced generator functionality in scatter_test.py

* replaced generator functionality in slice_test.py

* replaced generator functionality in conversion_with_layout_test.py

* replaced generator functionality in conversion_incorrect_models_test.py

* replaced generator functionality in conversion_basic_models_test.py

* replaced generator functionality in split_test.py

* replaced generator functionality in squeeze_test.py

* replaced generator functionality in mo_fallback_test_actual.py

* replaced generator functionality in layer_to_class_test.py

* replaced generator functionality in ir_engine_test.py

* replaced generator functionality in mo_fallback_test_tf_fe.py

* replaced generator functionality in freeze_placeholder_test.py

* replaced generator functionality in broadcasting_test.py

* replaced generator functionality in broadcasting_test.py

* replaced generator functionality in transpose_test.py

* replaced generator functionality in custom_replacement_config_test.py

* replaced generator functionality in unsqueeze_test.py

* replaced generator functionality in upsample_test.py

* replaced generator functionality in upsample_test.py

* Removed test-generator dependency from openvino/tools/constraints.txt

* replaced generator functionality in freeze_placeholder_test.py

* replaced generator functionality in conversion_incorrect_models_test.py

* removed test-generator from requirements_dev,constraints.txt,requirements.txt

* removed import generator from CorrectPaddingsForPadAfterComplex_test.py

* adding test_generator dep..

* revert back constraints.txt

* revert back requirements_dev

* pytest:- MatMulNormalizer_test.py

* pytest:- ShuffleChannelPatternOptimization_test.py

* pytest:- import_from_mo_test.py

* generator_to_pytest interpolate_reshape_test.py

* pytest:- rank_decomposer_test.py

* pytest:- size_replacer_test.py

* pytest:- concat_test.py

* pytest:- eltwise_test.py

* pytest:- utils_test.py

* pytest:- tdnn_component_replacer_test.py

* pytest:- MXFFTToDFT_test.py

* pytest:- activation_ext_test.py

* pytest:- AttributedSliceToSlice_test.py

* pytest:- squeeze_ext_test.py

* pytest:- transpose_ext_test.py

* pytest:- unsqueeze_ext_test.py

* pytest:- ObjectDetectionAPI_test.py

* pytest:- RFFTRealImagToRFFTSplit_test.py

* pytest:- TFFFTToDFT_test.py

* pytest:- WhereDecomposition_test.py

* pytest:- graph_test.py

* pytest:- ConvertGroupedStridedSlice_test.py

* dequantize_linear_resolver_test.py

* pytest:- FusedBatchNormTraining_test.py

* pytest:- L2NormFusing_test.py

* pytest:- PreserveRuntimeInfo_test.py

* pytest:- quantize_linear_resolver_test.py

* pytest:- UpsampleToResample_test.py

* pytest:- broadcast_test.py

* pytest:- cast_test.py

* pytest:- Complex_test.py

* pytest:- dft_signal_size_canonicalization_test.py

* pytest:- div_value_propagation_test.py

* pytest:- einsum_test.py

* pytest:- expand_dims_test.py

* pytest:- ExtractImagePatches_test.py

* pytest:- eye_test.py

* pytest:- gatherelements_test.py

* pytest:- If_test.py

* pytest:- interpolate_test.py

* pytest:- MatMul_test.py

* pytest:- MatMul_value_propagation_test.py

* pytest:- one_hot_test.py

* pytest:- ONNXResize11_test.py

* pytest:- ReduceOps_test.py

* pytest:- reshape_test.py

* scatter_test.py

* pytest:- slice_test.py

* pytest:- split_test.py

* pytest:- squeeze_test.py

* pytest:- transpose_test.py

* pytest:- unsqueeze_test.py

* pytest:- upsample_test.py

* pytest:- common_test.py

* pytest:- broadcasting_test.py

* revert back ir_engine_test.py

* revertback :- custom_replacement_config_test.py

* revertback:- mo_fallback_test_actual.py

* revertback:- mo_fallback_test_tf_fe.py

* pytest:- layer_to_class_test.py

* revertback:- conversion_basic_models_test.py

* revertback:- conversion_incorrect_models_test.py

* revertback:- conversion_with_layout_test

* revertback:- constraints.txt

* revertback:- loader_test.py

* pytest:- Pack_test.py

* revertback:- freeze_placeholder_test.py

---------

Co-authored-by: Andrei Kochin <andrei.kochin@intel.com>
This commit is contained in:
Pratham Ingawale 2023-10-10 14:12:49 +05:30 committed by GitHub
parent d205684aff
commit ed45a92e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 483 additions and 585 deletions

View File

@ -5,7 +5,7 @@ import unittest
from argparse import Namespace from argparse import Namespace
import numpy as np import numpy as np
from generator import generate, generator import pytest
from openvino.tools.mo.back.MatMulNormalizer import SmartReshape_HC_Reshape_MatMul, PullTransposeThroughFQUp from openvino.tools.mo.back.MatMulNormalizer import SmartReshape_HC_Reshape_MatMul, PullTransposeThroughFQUp
from openvino.tools.mo.ops.MatMul import MatMul from openvino.tools.mo.ops.MatMul import MatMul
@ -19,10 +19,9 @@ from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, val
from unit_tests.utils.graph import regular_op_with_empty_data as op_with_empty_data from unit_tests.utils.graph import regular_op_with_empty_data as op_with_empty_data
@generator class TestSmartReshape_HC_Reshape_MatMulTest():
class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase): @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern",
@generate( [
*[
([1, 20, 30], [30, 40], [20, -1], False, False, [-1, 30]), ([1, 20, 30], [30, 40], [20, -1], False, False, [-1, 30]),
([1, 20, 30], [40, 30], [20, -1], False, True, [-1, 30]), ([1, 20, 30], [40, 30], [20, -1], False, True, [-1, 30]),
([1, 30, 20], [30, 40], [-1, 20], True, False, [30, -1]), ([1, 30, 20], [30, 40], [-1, 20], True, False, [30, -1]),
@ -59,9 +58,9 @@ class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase):
graph_ref.clean_up() graph_ref.clean_up()
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
@generate(*[ @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern",[
([20, 30], [1, 30, 40], [-1, 40], False, False, [30, -1]), ([20, 30], [1, 30, 40], [-1, 40], False, False, [30, -1]),
([20, 30], [1, 40, 30], [40, -1], False, True, [-1, 30]), ([20, 30], [1, 40, 30], [40, -1], False, True, [-1, 30]),
([30, 20], [1, 30, 40], [-1, 40], True, False, [30, -1]), ([30, 20], [1, 30, 40], [-1, 40], True, False, [30, -1]),
@ -97,7 +96,7 @@ class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase):
graph_ref.clean_up() graph_ref.clean_up()
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
class FQTransposePullerTest(unittest.TestCase): class FQTransposePullerTest(unittest.TestCase):

View File

@ -1,10 +1,8 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
from argparse import Namespace from argparse import Namespace
import pytest
from generator import generate, generator
from openvino.tools.mo.back.ShuffleChannelPatternOptimization import ShuffleChannelFusion, DepthToSpaceFusion from openvino.tools.mo.back.ShuffleChannelPatternOptimization import ShuffleChannelFusion, DepthToSpaceFusion
from openvino.tools.mo.ops.depth_to_space import DepthToSpaceOp from openvino.tools.mo.ops.depth_to_space import DepthToSpaceOp
@ -18,8 +16,7 @@ from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_d
valued_const_with_data, connect, regular_op_with_empty_data valued_const_with_data, connect, regular_op_with_empty_data
@generator class TestShuffleChannelFusionTest():
class ShuffleChannelFusionTest(unittest.TestCase):
@staticmethod @staticmethod
def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group): def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group):
nodes = { nodes = {
@ -67,7 +64,7 @@ class ShuffleChannelFusionTest(unittest.TestCase):
return graph, graph_ref return graph, graph_ref
@generate(*[ @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[
([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2),
([2, 512, 7, 6], [2, 2, 256, 7, 6], [0, 2, 1, 3, 4], [2, 512, 7, 6], 2), ([2, 512, 7, 6], [2, 2, 256, 7, 6], [0, 2, 1, 3, 4], [2, 512, 7, 6], 2),
([1, 200, 200, 200], [1, 50, 4, 200, 200], [0, 2, 1, 3, 4], [1, 200, 200, 200], 50), ([1, 200, 200, 200], [1, 50, 4, 200, 200], [0, 2, 1, 3, 4], [1, 200, 200, 200], 50),
@ -77,11 +74,11 @@ class ShuffleChannelFusionTest(unittest.TestCase):
ShuffleChannelFusion().find_and_replace_pattern(graph) ShuffleChannelFusion().find_and_replace_pattern(graph)
graph.clean_up() graph.clean_up()
(flag, resp) = compare_graphs(graph, graph_ref, 'output') (flag, resp) = compare_graphs(graph, graph_ref, 'output')
self.assertTrue(flag, resp) assert flag, resp
self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \
graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels') graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels'
@generate(*[ @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[
([1, 512, 7, 6], [0, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [0, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2),
([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 4, 3], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 4, 3], [1, 512, 7, 6], 2),
([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [-1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [-1, 512, 7, 6], 2),
@ -91,11 +88,10 @@ class ShuffleChannelFusionTest(unittest.TestCase):
graph_ref = graph.copy() graph_ref = graph.copy()
ShuffleChannelFusion().find_and_replace_pattern(graph) ShuffleChannelFusion().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'output') (flag, resp) = compare_graphs(graph, graph_ref, 'output')
self.assertTrue(flag, resp) assert flag, resp
@generator class TestDepthToSpaceFusionTest():
class DepthToSpaceFusionTest(unittest.TestCase):
@staticmethod @staticmethod
def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size): def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size):
nodes = { nodes = {
@ -145,7 +141,7 @@ class DepthToSpaceFusionTest(unittest.TestCase):
return graph, graph_ref return graph, graph_ref
@generate(*[ @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size",[
([1, 512, 7, 6], [1, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([1, 512, 7, 6], [1, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2),
([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [2, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [2, 128, 14, 12], 2),
([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 5, 3], [1, 50, 400, 400], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 5, 3], [1, 50, 400, 400], 2),
@ -155,11 +151,11 @@ class DepthToSpaceFusionTest(unittest.TestCase):
DepthToSpaceFusion().find_and_replace_pattern(graph) DepthToSpaceFusion().find_and_replace_pattern(graph)
graph.clean_up() graph.clean_up()
(flag, resp) = compare_graphs(graph, graph_ref, 'output') (flag, resp) = compare_graphs(graph, graph_ref, 'output')
self.assertTrue(flag, resp) assert flag, resp
self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \
graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace') graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace'
@generate(*[ @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[
([1, 512, 7, 6], [0, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([1, 512, 7, 6], [0, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2),
([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [-1, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [-1, 128, 14, 12], 2),
([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 3, 5], [1, 50, 400, 400], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 3, 5], [1, 50, 400, 400], 2),
@ -169,4 +165,4 @@ class DepthToSpaceFusionTest(unittest.TestCase):
graph_ref = graph.copy() graph_ref = graph.copy()
DepthToSpaceFusion().find_and_replace_pattern(graph) DepthToSpaceFusion().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'output') (flag, resp) = compare_graphs(graph, graph_ref, 'output')
self.assertTrue(flag, resp) assert flag, resp

View File

@ -5,18 +5,16 @@ import os
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from generator import generator, generate import pytest
from openvino.runtime import serialize from openvino.runtime import serialize
from openvino.tools.mo import InputCutInfo, LayoutMap from openvino.tools.mo import InputCutInfo, LayoutMap
from openvino.tools.mo.utils.ir_engine.ir_engine import IREngine from openvino.tools.mo.utils.ir_engine.ir_engine import IREngine
from unit_tests.mo.unit_test_with_mocked_telemetry import UnitTestWithMockedTelemetry
from unit_tests.utils.graph import build_graph from unit_tests.utils.graph import build_graph
from utils import create_onnx_model, save_to_onnx from utils import create_onnx_model, save_to_onnx
@generator class TestConvertImportMOTest():
class ConvertImportMOTest(UnitTestWithMockedTelemetry):
test_directory = os.path.dirname(os.path.realpath(__file__)) test_directory = os.path.dirname(os.path.realpath(__file__))
@staticmethod @staticmethod
@ -79,7 +77,7 @@ class ConvertImportMOTest(UnitTestWithMockedTelemetry):
]) ])
return ref_graph return ref_graph
@generate(*[ @pytest.mark.parametrize("params",[
({}), ({}),
({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}), ({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}),
({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}), ({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}),

View File

@ -5,7 +5,6 @@ import os
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from generator import generator
from openvino.runtime import get_version as get_rt_version from openvino.runtime import get_version as get_rt_version
from openvino.runtime import serialize from openvino.runtime import serialize
@ -18,7 +17,6 @@ from utils import save_to_onnx
from openvino.tools.mo.utils.ir_reader.restore_graph import restore_graph_from_ir, save_restored_graph from openvino.tools.mo.utils.ir_reader.restore_graph import restore_graph_from_ir, save_restored_graph
@generator
class MetaDataTest(UnitTestWithMockedTelemetry): class MetaDataTest(UnitTestWithMockedTelemetry):
test_directory = os.path.dirname(os.path.realpath(__file__)) test_directory = os.path.dirname(os.path.realpath(__file__))

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.Pack import Pack from openvino.tools.mo.front.Pack import Pack
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -34,10 +33,10 @@ nodes_attributes = {
} }
@generator class TestPackTest():
class PackTest(unittest.TestCase):
@generate(*[(2, 2, 0), (3, 3, 0), (4, 4, 0), (4, 4, 1), (4, 1, 0), (4, 1, 1)]) @pytest.mark.parametrize("num_inputs, num_placeholders, axis", [(2, 2, 0), (3, 3, 0), (4, 4, 0),
(4, 4, 1), (4, 1, 0), (4, 1, 1)])
def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list): def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list):
graph_edges = [] graph_edges = []
@ -79,4 +78,4 @@ class PackTest(unittest.TestCase):
replacer.find_and_replace_pattern(graph) replacer.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generate, generator
from openvino.tools.mo.front.common.partial_infer.concat import concat_infer from openvino.tools.mo.front.common.partial_infer.concat import concat_infer
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors
@ -20,9 +19,9 @@ nodes_attributes = {'node_1': {'kind': 'data', 'value': None},
} }
@generator class TestConcatPartialInfer():
class TestConcatPartialInfer(unittest.TestCase): @pytest.mark.parametrize("shape1, shape2, output_shape, axis",[([1, 3, 227, 227], [1, 3, 220, 227],
@generate(*[([1, 3, 227, 227], [1, 3, 220, 227], [1, 3, 447, 227], 2), [1, 3, 447, 227], 2),
([1, 3, 227, 227], [1, 3, 227, 220], [1, 3, 227, 447], -1), ([1, 3, 227, 227], [1, 3, 227, 220], [1, 3, 227, 447], -1),
([1, 3, dynamic_dimension_value, 227], [1, dynamic_dimension_value, 227, 220], [1, 3, 227, 447], -1), ([1, 3, dynamic_dimension_value, 227], [1, dynamic_dimension_value, 227, 220], [1, 3, 227, 447], -1),
([1, 3, 10, 227], [1, 3, 10, dynamic_dimension_value], [1, 3, 10, dynamic_dimension_value], -1), ([1, 3, 10, 227], [1, 3, 10, dynamic_dimension_value], [1, 3, 10, dynamic_dimension_value], -1),
@ -43,9 +42,10 @@ class TestConcatPartialInfer(unittest.TestCase):
concat_node = Node(graph, 'concat') concat_node = Node(graph, 'concat')
concat_infer(concat_node) concat_infer(concat_node)
res_shape = graph.node['node_3']['shape'] res_shape = graph.node['node_3']['shape']
self.assertTrue(strict_compare_tensors(output_shape, res_shape)) assert strict_compare_tensors(output_shape, res_shape)
@generate(*[(shape_array([1]), shape_array([4]), shape_array([1, 4]), 0), @pytest.mark.parametrize("value1, value2, output_value, axis",[(shape_array([1]),
shape_array([4]), shape_array([1, 4]), 0),
(shape_array([dynamic_dimension_value]), shape_array([4]), (shape_array([dynamic_dimension_value]), shape_array([4]),
shape_array([dynamic_dimension_value, 4]), -1), shape_array([dynamic_dimension_value, 4]), -1),
]) ])
@ -65,7 +65,7 @@ class TestConcatPartialInfer(unittest.TestCase):
concat_node = Node(graph, 'concat') concat_node = Node(graph, 'concat')
concat_infer(concat_node) concat_infer(concat_node)
res_value = graph.node['node_3']['value'] res_value = graph.node['node_3']['value']
self.assertTrue(strict_compare_tensors(output_value, res_value)) assert strict_compare_tensors(output_value, res_value)
def test_concat_infer_not_match(self): def test_concat_infer_not_match(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -81,7 +81,7 @@ class TestConcatPartialInfer(unittest.TestCase):
}) })
concat_node = Node(graph, 'concat') concat_node = Node(graph, 'concat')
with self.assertRaisesRegex(Error, "Concat input shapes do not match for node*"): with pytest.raises(Error, match="Concat input shapes do not match for node*"):
concat_infer(concat_node) concat_infer(concat_node)
def test_concat_infer_no_shape(self): def test_concat_infer_no_shape(self):
@ -98,5 +98,5 @@ class TestConcatPartialInfer(unittest.TestCase):
}) })
concat_node = Node(graph, 'concat') concat_node = Node(graph, 'concat')
with self.assertRaisesRegex(Error, "One of the input shapes is not defined for node *"): with pytest.raises(Error, match="One of the input shapes is not defined for node *"):
concat_infer(concat_node) concat_infer(concat_node)

View File

@ -4,7 +4,7 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.common.partial_infer.eltwise import eltwise_infer, eltwise_reverse_infer from openvino.tools.mo.front.common.partial_infer.eltwise import eltwise_infer, eltwise_reverse_infer
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, strict_compare_tensors, \ from openvino.tools.mo.front.common.partial_infer.utils import shape_array, strict_compare_tensors, \
@ -24,9 +24,9 @@ nodes_attributes = {'node_1': {'value': 2, 'kind': 'data'},
} }
@generator
class TestEltwiseInfer(unittest.TestCase): class TestEltwiseInfer():
@generate(*[ @pytest.mark.parametrize("value1, shape1, value2, shape2, shape_infer, exp_value, exp_shape",[
(np.array(2), [], np.array(3), [], lambda a, b: np.multiply(a, b), np.array(6), []), (np.array(2), [], np.array(3), [], lambda a, b: np.multiply(a, b), np.array(6), []),
(np.array(2), [], np.array(3), [], lambda a, b: np.maximum(a, b), np.array(3), []), (np.array(2), [], np.array(3), [], lambda a, b: np.maximum(a, b), np.array(3), []),
(np.array(2), [], np.array(3), [], lambda a, b: np.add(a, b), np.array(5), []), (np.array(2), [], np.array(3), [], lambda a, b: np.add(a, b), np.array(5), []),
@ -67,8 +67,8 @@ class TestEltwiseInfer(unittest.TestCase):
res_shape = graph.node['node_3']['shape'] res_shape = graph.node['node_3']['shape']
res_value = eltwise_node.out_node().value res_value = eltwise_node.out_node().value
if exp_value is not None: if exp_value is not None:
self.assertTrue(strict_compare_tensors(res_value, shape_array(exp_value))) assert strict_compare_tensors(res_value, shape_array(exp_value))
self.assertTrue(strict_compare_tensors(res_shape, shape_array(exp_shape))) assert strict_compare_tensors(res_shape, shape_array(exp_shape))
def test_eltwise_infer_none_val(self): def test_eltwise_infer_none_val(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -89,9 +89,9 @@ class TestEltwiseInfer(unittest.TestCase):
res_shape = graph.node['node_3']['shape'] res_shape = graph.node['node_3']['shape']
res_value = eltwise_node.out_node().value res_value = eltwise_node.out_node().value
for i in range(0, len(exp_shape)): for i in range(0, len(exp_shape)):
self.assertEqual(exp_shape[i], res_shape[i]) assert exp_shape[i] == res_shape[i]
self.assertIsNone(res_value) assert res_value is None
def test_eltwise_infer_none_min_max(self): def test_eltwise_infer_none_min_max(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -107,7 +107,7 @@ class TestEltwiseInfer(unittest.TestCase):
graph.graph['layout'] = 'NCHW' graph.graph['layout'] = 'NCHW'
eltwise_node = Node(graph, 'eltw_1') eltwise_node = Node(graph, 'eltw_1')
with self.assertRaisesRegex(Error, 'Input shapes mismatch*'): with pytest.raises(Error, match='Input shapes mismatch*'):
eltwise_infer(eltwise_node) eltwise_infer(eltwise_node)

View File

@ -4,7 +4,7 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, mo_array, is_fully_defined, \ from openvino.tools.mo.front.common.partial_infer.utils import int64_array, mo_array, is_fully_defined, \
dynamic_dimension_value, dynamic_dimension, shape_array, compatible_shapes, shape_delete, shape_insert, \ dynamic_dimension_value, dynamic_dimension, shape_array, compatible_shapes, shape_delete, shape_insert, \
@ -26,9 +26,8 @@ def gen_masked_array(array, masked_indices):
return res return res
@generator class TestIsFullyDefinedTest():
class IsFullyDefinedTest(unittest.TestCase): @pytest.mark.parametrize("data, result",[(None, False),
@generate(*[(None, False),
(int64_array([2, 3, 5, 7]), True), # int64 array with valid values (int64_array([2, 3, 5, 7]), True), # int64 array with valid values
(np.array([2, 3, 5, 7]), True), # any numpy array with valid values (np.array([2, 3, 5, 7]), True), # any numpy array with valid values
(np.array([2, dynamic_dimension_value]), True), # array with dynamic dimension value is fully defined! (np.array([2, dynamic_dimension_value]), True), # array with dynamic dimension value is fully defined!
@ -42,12 +41,11 @@ class IsFullyDefinedTest(unittest.TestCase):
([dynamic_dimension, 1], False), # list with dynamic dimension is not fully defined ([dynamic_dimension, 1], False), # list with dynamic dimension is not fully defined
]) ])
def test_is_fully_defined(self, data, result): def test_is_fully_defined(self, data, result):
self.assertEqual(is_fully_defined(data), result) assert is_fully_defined(data) == result
@generator class TestShapeArrayTest():
class ShapeArrayTest(unittest.TestCase): @pytest.mark.parametrize("data, ref, result",[([1], shape_array([1]), True),
@generate(*[([1], shape_array([1]), True),
# if we provide a list with dynamic_dimension_value then it is converted to dynamic dimension # if we provide a list with dynamic_dimension_value then it is converted to dynamic dimension
([dynamic_dimension_value, 5], gen_masked_array([1, 5], [0]), True), ([dynamic_dimension_value, 5], gen_masked_array([1, 5], [0]), True),
# if we provide a list with dynamic_dimension then the generated shape array still have it # if we provide a list with dynamic_dimension then the generated shape array still have it
@ -56,12 +54,12 @@ class ShapeArrayTest(unittest.TestCase):
([2], gen_masked_array([1], []), False), ([2], gen_masked_array([1], []), False),
]) ])
def test_shape_array(self, data, ref, result): def test_shape_array(self, data, ref, result):
self.assertEqual(strict_compare_tensors(shape_array(data), ref), result) assert strict_compare_tensors(shape_array(data), ref) == result
@generator class TestCompareShapesTest():
class CompareShapesTest(unittest.TestCase): @pytest.mark.parametrize("input1, input2, result",[(gen_masked_array([1, 2, 3], []),
@generate(*[(gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2, 3], []), True), gen_masked_array([1, 2, 3], []), True),
(gen_masked_array([4, 2, 3], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([4, 2, 3], []), gen_masked_array([1, 2, 3], []), False),
(gen_masked_array([1, 2], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([1, 2], []), gen_masked_array([1, 2, 3], []), False),
(gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2], []), False), (gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2], []), False),
@ -75,12 +73,12 @@ class CompareShapesTest(unittest.TestCase):
(np.array([1, 2]), np.array([3, 2]), False), (np.array([1, 2]), np.array([3, 2]), False),
]) ])
def test_compare_shapes(self, input1, input2, result): def test_compare_shapes(self, input1, input2, result):
self.assertEqual(compatible_shapes(input1, input2), result) assert compatible_shapes(input1, input2) == result
@generator class TestShapeDeleteTest():
class ShapeDeleteTest(unittest.TestCase): @pytest.mark.parametrize("shape, indices, result",[(gen_masked_array([1, 2, 3], []), [],
@generate(*[(gen_masked_array([1, 2, 3], []), [], gen_masked_array([1, 2, 3], [])), gen_masked_array([1, 2, 3], [])),
# [1, d, 3] -> [d, 3]. Indices input is a list # [1, d, 3] -> [d, 3]. Indices input is a list
(gen_masked_array([1, 2, 3], [1]), [0], gen_masked_array([2, 3], [0])), (gen_masked_array([1, 2, 3], [1]), [0], gen_masked_array([2, 3], [0])),
# [1, d, 3] -> [d, 3]. Indices input is a numpy array # [1, d, 3] -> [d, 3]. Indices input is a numpy array
@ -103,16 +101,16 @@ class ShapeDeleteTest(unittest.TestCase):
(np.array([1, 2, 3, 4]), -2, [1, 2, 4]), # [1, 2, 3, 4] -> [1, 2, 4]. Negative index (np.array([1, 2, 3, 4]), -2, [1, 2, 4]), # [1, 2, 3, 4] -> [1, 2, 4]. Negative index
]) ])
def test_shape_delete(self, shape, indices, result): def test_shape_delete(self, shape, indices, result):
self.assertTrue(strict_compare_tensors(shape_delete(shape, indices), result)) assert strict_compare_tensors(shape_delete(shape, indices), result)
def test_shape_delete_raise_exception(self): def test_shape_delete_raise_exception(self):
with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): with pytest.raises(Error, match ='.*Incorrect parameter type.*'):
shape_delete(gen_masked_array([1, 2, 3], []), {}) shape_delete(gen_masked_array([1, 2, 3], []), {})
@generator class TestShapeInsertTest():
class ShapeInsertTest(unittest.TestCase): @pytest.mark.parametrize("shape, pos, values, result",[(gen_masked_array([1, 2, 3], []), 1, [5],
@generate(*[(gen_masked_array([1, 2, 3], []), 1, [5], gen_masked_array([1, 5, 2, 3], [])), gen_masked_array([1, 5, 2, 3], [])),
(gen_masked_array([1, 2, 3], [1]), 1, [5], gen_masked_array([1, 5, 2, 3], [2])), (gen_masked_array([1, 2, 3], [1]), 1, [5], gen_masked_array([1, 5, 2, 3], [2])),
(gen_masked_array([1, 2, 3], [1]), 1, [dynamic_dimension], gen_masked_array([1, 5, 2, 3], [1, 2])), (gen_masked_array([1, 2, 3], [1]), 1, [dynamic_dimension], gen_masked_array([1, 5, 2, 3], [1, 2])),
(gen_masked_array([1, 2, 3], [1]), 0, [dynamic_dimension], gen_masked_array([5, 1, 2, 3], [0, 2])), (gen_masked_array([1, 2, 3], [1]), 0, [dynamic_dimension], gen_masked_array([5, 1, 2, 3], [0, 2])),
@ -124,26 +122,25 @@ class ShapeInsertTest(unittest.TestCase):
(gen_masked_array([1], [0]), 0, [7, dynamic_dimension], gen_masked_array([7, 5, 2], [1, 2])), (gen_masked_array([1], [0]), 0, [7, dynamic_dimension], gen_masked_array([7, 5, 2], [1, 2])),
]) ])
def test_shape_insert(self, shape, pos, values, result): def test_shape_insert(self, shape, pos, values, result):
self.assertTrue(strict_compare_tensors(shape_insert(shape, pos, values), result)) assert strict_compare_tensors(shape_insert(shape, pos, values), result)
def test_shape_insert_raise_exception(self): def test_shape_insert_raise_exception(self):
with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): with pytest.raises(Error, match='.*Incorrect parameter type.*'):
shape_insert(gen_masked_array([1, 2, 3], []), 2, {}) shape_insert(gen_masked_array([1, 2, 3], []), 2, {})
@generator class Testmo_array_test():
class mo_array_test(unittest.TestCase): @pytest.mark.parametrize("data, result",[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])),
@generate(*[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])),
(mo_array([2., 3., 5., 7.], dtype=np.float64), np.array([2., 3., 5., 7.])), (mo_array([2., 3., 5., 7.], dtype=np.float64), np.array([2., 3., 5., 7.])),
(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.], dtype=np.float32)), (mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.], dtype=np.float32)),
]) ])
def test_mo_array_positive(self, data, result): def test_mo_array_positive(self, data, result):
self.assertEqual(data.dtype, result.dtype) assert data.dtype == result.dtype
@generate(*[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])), @pytest.mark.parametrize("data, result",[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])),
]) ])
def test_mo_array_negative(self, data, result): def test_mo_array_negative(self, data, result):
self.assertNotEqual(data.dtype, result.dtype) assert data.dtype != result.dtype
class clarify_partial_shape_test(unittest.TestCase): class clarify_partial_shape_test(unittest.TestCase):

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.interpolate_reshape import InterpolateWithConcat from openvino.tools.mo.front.interpolate_reshape import InterpolateWithConcat
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -39,8 +38,7 @@ nodes = {
} }
@generator class TestInterpolateConcat():
class TestInterpolateConcat(unittest.TestCase):
def test_interpolate_concat_reshape_graph_comparison(self): def test_interpolate_concat_reshape_graph_comparison(self):
graph = build_graph(nodes, [ graph = build_graph(nodes, [
*connect('placeholder', '0:interpolate'), *connect('placeholder', '0:interpolate'),
@ -64,7 +62,7 @@ class TestInterpolateConcat(unittest.TestCase):
*connect('concat', 'output'), *connect('concat', 'output'),
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_interpolate_identity_concat_reshape_graph_comparison(self): def test_interpolate_identity_concat_reshape_graph_comparison(self):
graph = build_graph(nodes, [ graph = build_graph(nodes, [
@ -97,7 +95,7 @@ class TestInterpolateConcat(unittest.TestCase):
*connect('concat', 'output'), *connect('concat', 'output'),
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_interpolate_concat_negate(self): def test_interpolate_concat_negate(self):
graph = build_graph(nodes, [ graph = build_graph(nodes, [
@ -120,9 +118,9 @@ class TestInterpolateConcat(unittest.TestCase):
*connect('identity_01', 'output_1'), *connect('identity_01', 'output_1'),
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
@generate(*[ @pytest.mark.parametrize("update_attrs",[
{'concat': {'axis': None}}, {'concat': {'axis': None}},
{'concat': {'axis': -1}}, {'concat': {'axis': -1}},
@ -148,7 +146,7 @@ class TestInterpolateConcat(unittest.TestCase):
], update_attributes=update_attrs, nodes_with_edges_only=True) ], update_attributes=update_attrs, nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_interpolate_tf_style_concat(self): def test_interpolate_tf_style_concat(self):
graph = build_graph(nodes, [ graph = build_graph(nodes, [
@ -161,4 +159,4 @@ class TestInterpolateConcat(unittest.TestCase):
graph_ref = graph.copy() graph_ref = graph.copy()
InterpolateWithConcat().find_and_replace_pattern(graph) InterpolateWithConcat().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,20 +1,18 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.kaldi.tdnn_component_replacer import TdnnComponentReplacer from openvino.tools.mo.front.kaldi.tdnn_component_replacer import TdnnComponentReplacer
from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
from unit_tests.utils.graph import build_graph, regular_op, result, connect_front, const from unit_tests.utils.graph import build_graph, regular_op, result, connect_front, const
@generator class TestTdnnComponentReplacerTest():
class TdnnComponentReplacerTest(unittest.TestCase):
@generate(*[ @pytest.mark.parametrize("weights, biases, time_offsets",[
([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1],),
([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1, 2, 10, 1000],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1, 2, 10, 1000],),
([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 0]), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 0]),
@ -72,4 +70,4 @@ class TdnnComponentReplacerTest(unittest.TestCase):
TdnnComponentReplacer().find_and_replace_pattern(graph) TdnnComponentReplacer().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -2,9 +2,7 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
from generator import generator, generate
from openvino.tools.mo.front.mxnet.MXFFTToDFT import MXFFTToDFT from openvino.tools.mo.front.mxnet.MXFFTToDFT import MXFFTToDFT
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -152,10 +150,8 @@ ref_converted_ifft_graph_edges = [
('abs', 'output'), ('abs', 'output'),
] ]
class TestMXFFTToDFTTest():
@generator @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])])
class MXFFTToDFTTest(unittest.TestCase):
@generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])])
def test_fft_replacement(self, input_shape): def test_fft_replacement(self, input_shape):
graph = build_graph(nodes_attrs=fft_graph_node_attrs, graph = build_graph(nodes_attrs=fft_graph_node_attrs,
edges=fft_graph_edges, edges=fft_graph_edges,
@ -170,9 +166,9 @@ class MXFFTToDFTTest(unittest.TestCase):
'placeholder': {'shape': input_shape} 'placeholder': {'shape': input_shape}
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output') (flag, resp) = compare_graphs(graph, ref_graph, 'output')
self.assertTrue(flag, resp) assert flag, resp
@generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])])
def test_ifft_replacement(self, input_shape): def test_ifft_replacement(self, input_shape):
graph = build_graph(nodes_attrs=fft_graph_node_attrs, graph = build_graph(nodes_attrs=fft_graph_node_attrs,
edges=fft_graph_edges, edges=fft_graph_edges,
@ -188,4 +184,4 @@ class MXFFTToDFTTest(unittest.TestCase):
'placeholder': {'shape': input_shape} 'placeholder': {'shape': input_shape}
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output') (flag, resp) = compare_graphs(graph, ref_graph, 'output')
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,19 +1,17 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.onnx.AttributedSliceToSlice import AttributedSliceToSliceReplacer from openvino.tools.mo.front.onnx.AttributedSliceToSlice import AttributedSliceToSliceReplacer
from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front
@generator class TestSliceReplacerTest():
class SliceReplacerTest(unittest.TestCase): @pytest.mark.parametrize("attributed_slice_attrs",[
@generate(*[
{'op': 'AttributedSlice', 'type': None, 'starts': np.array([0, 0]), 'ends': np.array([1, -1]), 'axes': np.array([0, 1])} {'op': 'AttributedSlice', 'type': None, 'starts': np.array([0, 0]), 'ends': np.array([1, -1]), 'axes': np.array([0, 1])}
]) ])
def test_attributed_slice_replacer(self, attributed_slice_attrs): def test_attributed_slice_replacer(self, attributed_slice_attrs):
@ -46,4 +44,4 @@ class SliceReplacerTest(unittest.TestCase):
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,11 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np import numpy as np
import onnx import onnx
from generator import generator, generate import pytest
import openvino.tools.mo.front.onnx.activation_ext as extractors import openvino.tools.mo.front.onnx.activation_ext as extractors
from openvino.tools.mo.ops.activation_ops import Elu from openvino.tools.mo.ops.activation_ops import Elu
@ -15,8 +13,7 @@ from unit_tests.utils.extractors import PB
from unit_tests.utils.graph import build_graph from unit_tests.utils.graph import build_graph
@generator class TestActivationOpsONNXExtractorTest():
class ActivationOpsONNXExtractorTest(unittest.TestCase):
@staticmethod @staticmethod
def _create_node(op_name: str): def _create_node(op_name: str):
pb = onnx.helper.make_node(op_name, ["X"], ["Y"]) pb = onnx.helper.make_node(op_name, ["X"], ["Y"])
@ -37,7 +34,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase):
status = out[key] == ref[key] status = out[key] == ref[key]
if type(status) in [list, np.ndarray]: if type(status) in [list, np.ndarray]:
status = np.all(status) status = np.all(status)
self.assertTrue(status, 'Mismatch for field {}, observed: {}, expected: {}'.format(key, out[key], ref[key])) assert status, f"Mismatch for field {key}, observed: {out[key]}, expected: {ref[key]}"
@staticmethod @staticmethod
def _extract(op_name): def _extract(op_name):
@ -45,7 +42,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase):
getattr(extractors, op_name + 'Extractor').extract(node) getattr(extractors, op_name + 'Extractor').extract(node)
return node.graph.node[node.id] return node.graph.node[node.id]
@generate(*['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin', @pytest.mark.parametrize("op_name",['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin',
'Sinh', 'Tan', 'Tanh']) 'Sinh', 'Tan', 'Tanh'])
def test_default(self, op_name): def test_default(self, op_name):
ref = self._base_attrs(op_name) ref = self._base_attrs(op_name)
@ -55,8 +52,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase):
self._match(out, ref) self._match(out, ref)
@generator class TestEluONNXExt():
class TestEluONNXExt(unittest.TestCase):
@staticmethod @staticmethod
def _create_elu_node(alpha=1.0): def _create_elu_node(alpha=1.0):
pb = onnx.helper.make_node( pb = onnx.helper.make_node(
@ -72,7 +68,7 @@ class TestEluONNXExt(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
Op.registered_ops['Elu'] = Elu Op.registered_ops['Elu'] = Elu
@generate(*[1.0, 2.0, 3.0]) @pytest.mark.parametrize("alpha",[1.0, 2.0, 3.0])
def test_elu_ext(self, alpha): def test_elu_ext(self, alpha):
node = self._create_elu_node(alpha) node = self._create_elu_node(alpha)
extractors.EluExtractor.extract(node) extractors.EluExtractor.extract(node)
@ -84,4 +80,4 @@ class TestEluONNXExt(unittest.TestCase):
} }
for key in exp_res.keys(): for key in exp_res.keys():
self.assertEqual(node[key], exp_res[key]) assert node[key] == exp_res[key]

View File

@ -1,11 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np import numpy as np
import onnx import onnx
from generator import generator, generate import pytest
from openvino.tools.mo.front.onnx.squeeze_ext import SqueezeFrontExtractor from openvino.tools.mo.front.onnx.squeeze_ext import SqueezeFrontExtractor
from openvino.tools.mo.ops.op import Op from openvino.tools.mo.ops.op import Op
@ -13,8 +11,7 @@ from openvino.tools.mo.ops.squeeze import Squeeze
from unit_tests.utils.extractors import PB from unit_tests.utils.extractors import PB
@generator class TestSqueezeONNXExt():
class TestSqueezeONNXExt(unittest.TestCase):
@staticmethod @staticmethod
def _create_squeeze_node(axes): def _create_squeeze_node(axes):
if axes is None: if axes is None:
@ -38,7 +35,7 @@ class TestSqueezeONNXExt(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
Op.registered_ops['Squeeze'] = Squeeze Op.registered_ops['Squeeze'] = Squeeze
@generate(*[[0, 1, 2, 3], [1], None]) @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], None])
def test_squeeze_ext(self, axes): def test_squeeze_ext(self, axes):
node = self._create_squeeze_node(axes) node = self._create_squeeze_node(axes)
SqueezeFrontExtractor.extract(node) SqueezeFrontExtractor.extract(node)
@ -50,6 +47,6 @@ class TestSqueezeONNXExt(unittest.TestCase):
for key in exp_res.keys(): for key in exp_res.keys():
if type(node[key]) in [list, np.ndarray]: if type(node[key]) in [list, np.ndarray]:
self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) assert np.array_equal(np.array(node[key]), np.array(exp_res[key]))
else: else:
self.assertEqual(node[key], exp_res[key]) assert node[key] == exp_res[key]

View File

@ -2,11 +2,10 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import itertools import itertools
import unittest import pytest
import numpy as np import numpy as np
import onnx import onnx
from generator import generator, generate
from openvino.tools.mo.front.onnx.transpose_ext import TransposeFrontExtractor from openvino.tools.mo.front.onnx.transpose_ext import TransposeFrontExtractor
from openvino.tools.mo.ops.transpose import Transpose from openvino.tools.mo.ops.transpose import Transpose
@ -14,8 +13,7 @@ from openvino.tools.mo.ops.op import Op
from unit_tests.utils.extractors import PB from unit_tests.utils.extractors import PB
@generator class TestTransposeONNXExt():
class TestTransposeONNXExt(unittest.TestCase):
@staticmethod @staticmethod
def _create_transpose_node(order: list): def _create_transpose_node(order: list):
if order is None: if order is None:
@ -42,7 +40,7 @@ class TestTransposeONNXExt(unittest.TestCase):
pass pass
# This generator generates all permutations for [0,1,2,3] and [0,1,2] orders # This generator generates all permutations for [0,1,2,3] and [0,1,2] orders
@generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))] + @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))] +
[list(order) for order in list(itertools.permutations(np.arange(3)))] + [None]) [list(order) for order in list(itertools.permutations(np.arange(3)))] + [None])
def test_transpose_ext(self, order): def test_transpose_ext(self, order):
node = self._create_transpose_node(order) node = self._create_transpose_node(order)
@ -56,7 +54,7 @@ class TestTransposeONNXExt(unittest.TestCase):
for key in exp_res.keys(): for key in exp_res.keys():
if isinstance(exp_res[key], list): if isinstance(exp_res[key], list):
self.assertTrue(np.array_equal(node[key], exp_res[key]), assert np.array_equal(node[key], exp_res[key]),\
"Orders are not the same: {} and {}".format(node[key], exp_res[key])) "Orders are not the same: {} and {}".format(node[key], exp_res[key])
else: else:
self.assertEqual(node[key], exp_res[key]) assert node[key] == exp_res[key]

View File

@ -1,11 +1,10 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
import onnx import onnx
from generator import generator, generate
from openvino.tools.mo.front.onnx.unsqueeze_ext import UnsqueezeFrontExtractor from openvino.tools.mo.front.onnx.unsqueeze_ext import UnsqueezeFrontExtractor
from openvino.tools.mo.ops.op import Op from openvino.tools.mo.ops.op import Op
@ -13,8 +12,7 @@ from openvino.tools.mo.ops.unsqueeze import Unsqueeze
from unit_tests.utils.extractors import PB from unit_tests.utils.extractors import PB
@generator class TestUnsqueezeONNXExt():
class TestUnsqueezeONNXExt(unittest.TestCase):
@staticmethod @staticmethod
def _create_unsqueeze_node(axes): def _create_unsqueeze_node(axes):
if axes is None: if axes is None:
@ -38,7 +36,7 @@ class TestUnsqueezeONNXExt(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
Op.registered_ops['Unsqueeze'] = Unsqueeze Op.registered_ops['Unsqueeze'] = Unsqueeze
@generate(*[[0, 1, 2, 3], [1], []]) @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], []])
def test_unsqueeze_ext(self, axes): def test_unsqueeze_ext(self, axes):
node = self._create_unsqueeze_node(axes) node = self._create_unsqueeze_node(axes)
UnsqueezeFrontExtractor.extract(node) UnsqueezeFrontExtractor.extract(node)
@ -49,6 +47,6 @@ class TestUnsqueezeONNXExt(unittest.TestCase):
for key in exp_res.keys(): for key in exp_res.keys():
if type(node[key]) in [list, np.ndarray]: if type(node[key]) in [list, np.ndarray]:
self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) assert np.array_equal(np.array(node[key]), np.array(exp_res[key]))
else: else:
self.assertEqual(node[key], exp_res[key]) assert node[key] == exp_res[key]

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.rank_decomposer import RankDecomposer from openvino.tools.mo.front.rank_decomposer import RankDecomposer
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -24,10 +23,9 @@ nodes = lambda output_type: {
} }
@generator class TestRankDecomposerTest():
class RankDecomposerTest(unittest.TestCase):
@generate(np.int32, np.int64) @pytest.mark.parametrize("output_type", [np.int32, np.int64])
def test_rank_decomposer(self, output_type): def test_rank_decomposer(self, output_type):
graph = build_graph(nodes_attrs=nodes(output_type), edges=[ graph = build_graph(nodes_attrs=nodes(output_type), edges=[
*connect('input', 'rank'), *connect('input', 'rank'),
@ -44,9 +42,9 @@ class RankDecomposerTest(unittest.TestCase):
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
self.assertEqual(graph.get_op_nodes(type='Squeeze')[0]['name'], 'my_rank', assert graph.get_op_nodes(type='Squeeze')[0]['name'] == 'my_rank',\
'Name is not inherited from original node for RankDecomposer') 'Name is not inherited from original node for RankDecomposer'
print(output_type) print(output_type)
def test_rank_decomposer_assertion(self): def test_rank_decomposer_assertion(self):
@ -54,4 +52,5 @@ class RankDecomposerTest(unittest.TestCase):
*connect('input', 'rank'), *connect('input', 'rank'),
*connect('rank', 'output'), *connect('rank', 'output'),
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
self.assertRaises(AssertionError, RankDecomposer().find_and_replace_pattern, graph) with pytest.raises(AssertionError):
RankDecomposer().find_and_replace_pattern (graph)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.SizeReplacer import SizeFrontReplacer from openvino.tools.mo.front.SizeReplacer import SizeFrontReplacer
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -23,10 +22,9 @@ nodes = lambda output_type: {
} }
@generator class TestSizeReplacerTest():
class SizeReplacerTest(unittest.TestCase):
@generate(np.int32, np.int64) @pytest.mark.parametrize("output_type" ,[np.int32, np.int64])
def test_size_replacer(self, output_type): def test_size_replacer(self, output_type):
graph = build_graph(nodes_attrs=nodes(output_type), edges=[ graph = build_graph(nodes_attrs=nodes(output_type), edges=[
*connect('input', 'size'), *connect('input', 'size'),
@ -42,9 +40,9 @@ class SizeReplacerTest(unittest.TestCase):
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
self.assertEqual(graph.get_op_nodes(type='ReduceProd')[0]['name'], 'my_size', assert graph.get_op_nodes(type='ReduceProd')[0]['name'] == 'my_size',\
'Name is not inherited from original node for SizeReplacer') 'Name is not inherited from original node for SizeReplacer'
print(output_type) print(output_type)
def test_size_replacer_assertion(self): def test_size_replacer_assertion(self):
@ -52,4 +50,5 @@ class SizeReplacerTest(unittest.TestCase):
*connect('input', 'size'), *connect('input', 'size'),
*connect('size', 'output'), *connect('size', 'output'),
], nodes_with_edges_only=True) ], nodes_with_edges_only=True)
self.assertRaises(AssertionError, SizeFrontReplacer().find_and_replace_pattern, graph) with pytest.raises(AssertionError):
SizeFrontReplacer().find_and_replace_pattern (graph)

View File

@ -5,7 +5,6 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.tf.CorrectPaddingsForPadAfterComplex import CorrectPaddingsForPadAfterComplex from openvino.tools.mo.front.tf.CorrectPaddingsForPadAfterComplex import CorrectPaddingsForPadAfterComplex
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array

View File

@ -6,7 +6,7 @@ from argparse import Namespace
from unittest.mock import patch from unittest.mock import patch
import os import os
from generator import generator, generate import pytest
from openvino.tools.mo.front.tf.ObjectDetectionAPI import calculate_shape_keeping_aspect_ratio, \ from openvino.tools.mo.front.tf.ObjectDetectionAPI import calculate_shape_keeping_aspect_ratio, \
calculate_placeholder_spatial_shape, ObjectDetectionAPIPreprocessor2Replacement calculate_placeholder_spatial_shape, ObjectDetectionAPIPreprocessor2Replacement
@ -31,12 +31,11 @@ class FakePipelineConfig:
return self._model_params[param] return self._model_params[param]
@generator class TestCalculateShape():
class TestCalculateShape(unittest.TestCase):
min_size = 600 min_size = 600
max_size = 1024 max_size = 1024
@generate(*[(100, 300, 341, 1024), @pytest.mark.parametrize("h, w, th, tw",[(100, 300, 341, 1024),
(100, 600, 171, 1024), (100, 600, 171, 1024),
(100, 3000, 34, 1024), (100, 3000, 34, 1024),
(300, 300, 600, 600), (300, 300, 600, 600),
@ -53,7 +52,7 @@ class TestCalculateShape(unittest.TestCase):
(2000, 1800, 667, 600), (2000, 1800, 667, 600),
]) ])
def test_calculate_shape(self, h, w, th, tw): def test_calculate_shape(self, h, w, th, tw):
self.assertTupleEqual(calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size), (th, tw)) assert calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size) == (th, tw)
class TestCalculatePlaceholderSpatialShape(unittest.TestCase): class TestCalculatePlaceholderSpatialShape(unittest.TestCase):

View File

@ -1,10 +1,7 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import pytest
import unittest
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.front.tf.RFFTRealImagToRFFTSplit import RFFTRealImagToRDFTSplit from openvino.tools.mo.front.tf.RFFTRealImagToRFFTSplit import RFFTRealImagToRDFTSplit
@ -85,9 +82,8 @@ ref_graph_edges = [
] ]
@generator class TestRFFTRealImagToRFFTSplitTest():
class RFFTRealImagToRFFTSplitTest(unittest.TestCase): @pytest.mark.parametrize("num_of_dims",[1, 2, 3])
@generate(*[1, 2, 3])
def test_replacement(self, num_of_dims): def test_replacement(self, num_of_dims):
graph = build_graph(nodes_attrs=graph_node_attrs, graph = build_graph(nodes_attrs=graph_node_attrs,
edges=graph_edges, edges=graph_edges,
@ -102,4 +98,4 @@ class RFFTRealImagToRFFTSplitTest(unittest.TestCase):
'rfft': {'num_of_dimensions': num_of_dims} 'rfft': {'num_of_dimensions': num_of_dims}
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -2,9 +2,7 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.front.tf.TFFFTToDFT import TFFFTToDFT from openvino.tools.mo.front.tf.TFFFTToDFT import TFFFTToDFT
@ -83,9 +81,8 @@ ref_dft_graph_with_signal_size_edges = [
] ]
@generator class TestTFFFTToDFTTest():
class TFFFTToDFTTest(unittest.TestCase): @pytest.mark.parametrize("num_of_dimensions, dft_type, fft_axes",[(2, 'DFT', int64_array([-2, -1])),
@generate(*[(2, 'DFT', int64_array([-2, -1])),
(2, 'IDFT', int64_array([-2, -1])), (2, 'IDFT', int64_array([-2, -1])),
(1, 'DFT', int64_array([-1])), (1, 'DFT', int64_array([-1])),
(1, 'IDFT', int64_array([-1])), (1, 'IDFT', int64_array([-1])),
@ -113,9 +110,9 @@ class TFFFTToDFTTest(unittest.TestCase):
'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)},
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
@generate(*[ @pytest.mark.parametrize("num_of_dims, fft_kind, fft_axes, input_shape, signal_size",[
(2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([100, -1])), (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([100, -1])),
(2, 'IRDFT', int64_array([-2, -1]), int64_array([3, 100, 100, 2]), int64_array([100, -1])), (2, 'IRDFT', int64_array([-2, -1]), int64_array([3, 100, 100, 2]), int64_array([100, -1])),
(2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([95, 116])), (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([95, 116])),
@ -159,4 +156,4 @@ class TFFFTToDFTTest(unittest.TestCase):
'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)},
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,12 +1,10 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.tf.WhereDecomposition import WhereDecomposition from openvino.tools.mo.front.tf.WhereDecomposition import WhereDecomposition
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
@ -64,9 +62,8 @@ ref_graph_edges = [
] ]
@generator class TestTFWhereDecompositionTest():
class TFWhereDecompositionTest(unittest.TestCase): @pytest.mark.parametrize("input_shape",[[1, 100, 120, 150], [16, 125, 14]])
@generate(*[[1, 100, 120, 150], [16, 125, 14]])
def test_1(self, input_shape): def test_1(self, input_shape):
in_shape = int64_array(input_shape) in_shape = int64_array(input_shape)
graph = build_graph(graph_node_attrs, graph = build_graph(graph_node_attrs,
@ -81,4 +78,4 @@ class TFWhereDecompositionTest(unittest.TestCase):
'placeholder_data': {'shape': in_shape} 'placeholder_data': {'shape': in_shape}
}) })
(flag, resp) = compare_graphs(graph, ref_graph, 'output') (flag, resp) = compare_graphs(graph, ref_graph, 'output')
self.assertTrue(flag, resp) assert flag,resp

View File

@ -4,7 +4,7 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, \ from openvino.tools.mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, \
set_edge_attribute_between_nodes set_edge_attribute_between_nodes
@ -364,8 +364,7 @@ class TestGraphShapeChecker(unittest.TestCase):
graph.check_shapes_consistency() graph.check_shapes_consistency()
@generator class TestGraphPortsChecker():
class TestGraphPortsChecker(unittest.TestCase):
nodes = { nodes = {
'0': {'type': 'Parameter', 'value': None, 'kind': 'op', 'op': 'Parameter'}, '0': {'type': 'Parameter', 'value': None, 'kind': 'op', 'op': 'Parameter'},
'0_data': {'value': None, 'shape': None, 'kind': 'data'}, '0_data': {'value': None, 'shape': None, 'kind': 'data'},
@ -380,7 +379,7 @@ class TestGraphPortsChecker(unittest.TestCase):
'3_data': {'value': None, 'shape': None, 'kind': 'data'}, '3_data': {'value': None, 'shape': None, 'kind': 'data'},
} }
@generate(*[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)]) @pytest.mark.parametrize("node_id, port_type, port_idx",[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)])
def test_check_shape_consistency_1(self, node_id: str, port_type: str, port_idx: int): def test_check_shape_consistency_1(self, node_id: str, port_type: str, port_idx: int):
# #
# ,->2-->2_data---,->3-->3_data # ,->2-->2_data---,->3-->3_data
@ -404,7 +403,7 @@ class TestGraphPortsChecker(unittest.TestCase):
else: else:
node.add_output_port(idx=port_idx) node.add_output_port(idx=port_idx)
with self.assertRaisesRegex(Error, "Node {} has not consecutive {} ports indexes:.*".format(node_id, with pytest.raises (Error, match= "Node {} has not consecutive {} ports indexes:.*".format(node_id,
port_type)): port_type)):
graph.check_nodes_ports_are_consecutive() graph.check_nodes_ports_are_consecutive()
@ -1864,4 +1863,5 @@ class TestTopologicalSort(unittest.TestCase):
stat_node = Node(graph, "E") stat_node = Node(graph, "E")
nodes_names = [node.name for node in graph.pseudo_topological_sort_with_start_node(start_node=stat_node, nodes_names = [node.name for node in graph.pseudo_topological_sort_with_start_node(start_node=stat_node,
reverse=True)] reverse=True)]
assert nodes_names == ['E'] assert nodes_names == ['E']

View File

@ -4,7 +4,7 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.middle.ConvertGroupedStridedSlice import ConvertGroupedStridedSlice from openvino.tools.mo.middle.ConvertGroupedStridedSlice import ConvertGroupedStridedSlice
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value
@ -108,8 +108,7 @@ one_strided_slice_case_edges = [
] ]
@generator class TestConvertGroupedStridedSliceTests():
class ConvertGroupedStridedSliceTests(unittest.TestCase):
def test_1(self): def test_1(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
[('placeholder_1', 'placeholder_1_data'), [('placeholder_1', 'placeholder_1_data'),
@ -172,7 +171,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
ConvertGroupedStridedSlice().find_and_replace_pattern(graph) ConvertGroupedStridedSlice().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_2(self): def test_2(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -236,7 +235,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Intersection of split ranges in feature dimension # Intersection of split ranges in feature dimension
def test_3_neg(self): def test_3_neg(self):
@ -307,7 +306,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Split range overflow in feature dimension # Split range overflow in feature dimension
def test_4_neg(self): def test_4_neg(self):
@ -377,7 +376,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
ConvertGroupedStridedSlice().find_and_replace_pattern(graph) ConvertGroupedStridedSlice().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Split(1,H,W,54)--->Fake_data (1,H,W,1) # Split(1,H,W,54)--->Fake_data (1,H,W,1)
# |`---->Sslice1_out (1,H,W,18) # |`---->Sslice1_out (1,H,W,18)
@ -447,7 +446,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
ConvertGroupedStridedSlice().find_and_replace_pattern(graph) ConvertGroupedStridedSlice().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Split(1,H,W,54) # Split(1,H,W,54)
# |`---->Sslice1_out (1,H,W,(0,18)) # |`---->Sslice1_out (1,H,W,(0,18))
@ -511,7 +510,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
ConvertGroupedStridedSlice().find_and_replace_pattern(graph) ConvertGroupedStridedSlice().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_7_neg(self): def test_7_neg(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -567,7 +566,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Split(1,54,W,C) # Split(1,54,W,C)
# |`---->Sslice1_out (1,(0,18),W,C) # |`---->Sslice1_out (1,(0,18),W,C)
@ -628,10 +627,10 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Test for the case when there is only 1 StridedSlice. # Test for the case when there is only 1 StridedSlice.
@generate(*[(np.array([1, 227, 227, 54]), @pytest.mark.parametrize("input_shape, slices, output_shape",[(np.array([1, 227, 227, 54]),
np.array([slice(0, 1, 1), slice(0, 227, 1), slice(0, 227, 1), slice(0, 18, 1)]), np.array([slice(0, 1, 1), slice(0, 227, 1), slice(0, 227, 1), slice(0, 18, 1)]),
np.array([1, 227, 227, 18])), np.array([1, 227, 227, 18])),
(np.array([57, 16, 100, 23]), (np.array([57, 16, 100, 23]),
@ -659,7 +658,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern = ConvertGroupedStridedSlice() pattern = ConvertGroupedStridedSlice()
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'op_output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'op_output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# Test for case when # Test for case when
# 1) There are 4 StridedSlice operations. # 1) There are 4 StridedSlice operations.
@ -763,7 +762,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern = ConvertGroupedStridedSlice() pattern = ConvertGroupedStridedSlice()
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# dynamic slice # dynamic slice
def test_11(self): def test_11(self):
@ -804,7 +803,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
# one unuque StridedSlice # one unuque StridedSlice
def test_12(self): def test_12(self):
@ -841,9 +840,9 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase):
pattern.find_and_replace_pattern(graph) pattern.find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'sslice_1_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_1_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
(flag, resp) = compare_graphs(graph, graph_ref, 'sslice_2_data', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_2_data', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
class AddReshapeAfterStridedSliceTests(unittest.TestCase): class AddReshapeAfterStridedSliceTests(unittest.TestCase):

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.middle.FusedBatchNormTraining import FusedBatchNormTraining from openvino.tools.mo.middle.FusedBatchNormTraining import FusedBatchNormTraining
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -71,9 +70,8 @@ nodes_attributes = {
} }
@generator class TestFusedBatchNormTrainingTest():
class FusedBatchNormTrainingTest(unittest.TestCase): @pytest.mark.parametrize("op",[
@generate(*[
'FusedBatchNorm', 'FusedBatchNormV2', 'FusedBatchNormV3', 'FusedBatchNorm', 'FusedBatchNormV2', 'FusedBatchNormV3',
]) ])
def test_transformation(self, op: str): def test_transformation(self, op: str):
@ -137,7 +135,7 @@ class FusedBatchNormTrainingTest(unittest.TestCase):
graph_ref.nodes['batchnorm']['op'] = op graph_ref.nodes['batchnorm']['op'] = op
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_non_training(self): def test_non_training(self):
graph = build_graph(nodes_attributes, graph = build_graph(nodes_attributes,
@ -161,4 +159,4 @@ class FusedBatchNormTrainingTest(unittest.TestCase):
shape_inference(graph) shape_inference(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.middle.L2NormFusing import L2NormToNorm from openvino.tools.mo.middle.L2NormFusing import L2NormToNorm
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -67,9 +66,9 @@ edges_after_replacement = [
] ]
@generator class TestL2NormToNormTest():
class L2NormToNormTest(unittest.TestCase): @pytest.mark.parametrize("input_shape, axes, layout",
@generate(*[(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension [(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension
(int64_array([2, 3]), int64_array([1]), 'NHWC'), # NC layout, normalize C dimension (int64_array([2, 3]), int64_array([1]), 'NHWC'), # NC layout, normalize C dimension
(int64_array([2, 3, 5]), int64_array([1]), 'NCHW'), # NCH layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NCHW'), # NCH layout, normalize C dimension
(int64_array([2, 3, 5]), int64_array([1]), 'NHWC'), # NCH layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NHWC'), # NCH layout, normalize C dimension
@ -102,10 +101,11 @@ class L2NormToNormTest(unittest.TestCase):
], edges_after_replacement, nodes_with_edges_only=True) ], edges_after_replacement, nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name') assert (graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name')
self.assertTrue(flag, resp) assert flag, resp
@generate(*[(int64_array([2]), int64_array([0]), 'NCHW'), @pytest.mark.parametrize("input_shape, axes, layout",
[(int64_array([2]), int64_array([0]), 'NCHW'),
(int64_array([2, 3]), int64_array([0]), 'NCHW'), (int64_array([2, 3]), int64_array([0]), 'NCHW'),
(int64_array([2, 3]), int64_array([0]), 'NHWC'), (int64_array([2, 3]), int64_array([0]), 'NHWC'),
(int64_array([2, 3]), int64_array([0, 1]), 'NCHW'), (int64_array([2, 3]), int64_array([0, 1]), 'NCHW'),
@ -161,4 +161,4 @@ class L2NormToNormTest(unittest.TestCase):
], edges, nodes_with_edges_only=True) ], edges, nodes_with_edges_only=True)
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.elemental import copy_shape_infer from openvino.tools.mo.front.common.partial_infer.elemental import copy_shape_infer
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -94,9 +93,8 @@ edges_with_transpose_for_case_with_two_results = [
] ]
@generator class TestPreserveRuntimeInfoTest():
class PreserveRuntimeInfoTest(unittest.TestCase): @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order, add_permutation_attrs",[
@generate(*[
([0, 3, 1, 2], [0, 2, 3, 1], True), ([0, 3, 1, 2], [0, 2, 3, 1], True),
([0, 4, 1, 2, 3], [0, 2, 3, 4, 1], True), ([0, 4, 1, 2, 3], [0, 2, 3, 4, 1], True),
(None, None, False), (None, None, False),
@ -135,19 +133,19 @@ class PreserveRuntimeInfoTest(unittest.TestCase):
PreserveRuntimeInfo().find_and_replace_pattern(graph) PreserveRuntimeInfo().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'result') (flag, resp) = compare_graphs(graph, graph_ref, 'result')
self.assertTrue(flag, resp) assert flag, resp
self.assertFalse(param_node.has_valid('permute_attrs')) assert not param_node.has_valid('permute_attrs')
self.assertFalse(param_node.out_node(0).has_valid('permutation')) assert not param_node.out_node(0).has_valid('permutation')
if add_permutation_attrs: if add_permutation_attrs:
rt_info = param_node.rt_info.info rt_info = param_node.rt_info.info
old_api_map = rt_info[('old_api_map_order', 0)].info old_api_map = rt_info[('old_api_map_order', 0)].info
self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)
rt_info = result_node.rt_info.info rt_info = result_node.rt_info.info
old_api_map = rt_info[('old_api_map_order', 0)].info old_api_map = rt_info[('old_api_map_order', 0)].info
self.assertTrue(np.array_equal(old_api_map['order'], nhwc_to_nchw_order)) assert np.array_equal(old_api_map['order'], nhwc_to_nchw_order)
def test_auto_disable_nhwc_to_nchw(self): def test_auto_disable_nhwc_to_nchw(self):
shape_len = 4 shape_len = 4
@ -173,18 +171,18 @@ class PreserveRuntimeInfoTest(unittest.TestCase):
PreserveRuntimeInfo().find_and_replace_pattern(graph) PreserveRuntimeInfo().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'result') (flag, resp) = compare_graphs(graph, graph_ref, 'result')
self.assertTrue(flag, resp) assert flag, resp
rt_info = param_node.rt_info.info rt_info = param_node.rt_info.info
old_api_map = rt_info[('old_api_map_order', 0)].info old_api_map = rt_info[('old_api_map_order', 0)].info
self.assertTrue(np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1])) assert np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1])
rt_info = result_node.rt_info.info rt_info = result_node.rt_info.info
old_api_map = rt_info[('old_api_map_order', 0)].info old_api_map = rt_info[('old_api_map_order', 0)].info
self.assertTrue(np.array_equal(old_api_map['order'], [0, 3, 1, 2])) assert np.array_equal(old_api_map['order'], [0, 3, 1, 2])
@generate(*[ @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order,add_permutation_attrs, fft_kind",
([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'), [([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'),
([0, 3, 1, 2], [0, 2, 3, 1], True, 'IDFT'), ([0, 3, 1, 2], [0, 2, 3, 1], True, 'IDFT'),
(None, None, False, 'DFT'), (None, None, False, 'DFT'),
(None, None, False, 'IDFT'), (None, None, False, 'IDFT'),
@ -235,12 +233,12 @@ class PreserveRuntimeInfoTest(unittest.TestCase):
PreserveRuntimeInfo().find_and_replace_pattern(graph) PreserveRuntimeInfo().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'result1') (flag, resp) = compare_graphs(graph, graph_ref, 'result1')
self.assertTrue(flag, resp) assert flag, resp
self.assertFalse(param1_node.has_valid('permute_attrs')) assert not param1_node.has_valid('permute_attrs')
self.assertFalse(param1_node.out_node(0).has_valid('permutation')) assert not param1_node.out_node(0).has_valid('permutation')
if add_permutation_attrs: if add_permutation_attrs:
rt_info = param1_node.rt_info.info rt_info = param1_node.rt_info.info
old_api_map = rt_info[('old_api_map_order', 0)].info old_api_map = rt_info[('old_api_map_order', 0)].info
self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.middle.UpsampleToResample import UpsampleToResample from openvino.tools.mo.middle.UpsampleToResample import UpsampleToResample
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float32_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float32_array
@ -143,9 +142,8 @@ ref_graph_edges = [
] ]
@generator class TestUpsampleToResampleTest():
class UpsampleToResampleTest(unittest.TestCase): @pytest.mark.parametrize("input_shape, scales, axes",[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]),
@generate(*[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]),
([2, 20, 30, 40], [1, 1, 3, 3], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 3], [2, 3]),
([2, 10, 20, 30], [1, 1, 6, 5], [2, 3]), ([2, 10, 20, 30], [1, 1, 6, 5], [2, 3]),
([2, 20, 30, 40], [1, 1, 3, 4], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 4], [2, 3]),
@ -193,9 +191,9 @@ class UpsampleToResampleTest(unittest.TestCase):
}) })
UpsampleToResample().find_and_replace_pattern(graph) UpsampleToResample().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, ref_graph, 'output') (flag, resp) = compare_graphs(graph, ref_graph, 'output')
self.assertTrue(flag, resp) assert flag, resp
@generate(*[([2, 10, 20, 30], [1, 2, 5, 5],), @pytest.mark.parametrize("input_shape, scales",[([2, 10, 20, 30], [1, 2, 5, 5],),
([2, 3, 20, 30, 40], [1, 2, 3, 3, 3],), ([2, 3, 20, 30, 40], [1, 2, 3, 3, 3],),
]) ])
def test_pattern_does_not_satisfy(self, input_shape, scales): def test_pattern_does_not_satisfy(self, input_shape, scales):
@ -214,4 +212,4 @@ class UpsampleToResampleTest(unittest.TestCase):
UpsampleToResample().find_and_replace_pattern(graph) UpsampleToResample().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, ref_graph, 'output') (flag, resp) = compare_graphs(graph, ref_graph, 'output')
self.assertTrue(flag, resp) assert flag, resp

View File

@ -9,7 +9,7 @@ from openvino.tools.mo.middle.dequantize_linear_resolver import DequantizeLinear
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
from unit_tests.utils.graph import build_graph from unit_tests.utils.graph import build_graph
from generator import generator, generate import pytest
nodes1_attributes = { nodes1_attributes = {
'input': {'kind': 'op', 'op': 'AnyOp'}, 'input': {'kind': 'op', 'op': 'AnyOp'},
@ -145,9 +145,9 @@ class TestDequantizeLinearResolver(unittest.TestCase):
(flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True)
self.assertTrue(flag, resp) self.assertTrue(flag, resp)
@generator class TestDequantizeWithAxis():
class TestDequantizeWithAxis(unittest.TestCase): @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value, target_shape, axis",
@generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32),
np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), 2), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), 2),
(int64_array([1, 3, 4, 4]), int64_array([2, 3, 4, 5]), (int64_array([1, 3, 4, 4]), int64_array([2, 3, 4, 5]),
np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 3, 1, 1]), 1), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 3, 1, 1]), 1),
@ -234,4 +234,4 @@ class TestDequantizeWithAxis(unittest.TestCase):
DequantizeLinearResolver().find_and_replace_pattern(graph) DequantizeLinearResolver().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -9,7 +9,7 @@ from openvino.tools.mo.middle.quantize_linear_resolver import QuantizeLinearReso
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
from unit_tests.utils.graph import build_graph from unit_tests.utils.graph import build_graph
from generator import generator, generate import pytest
nodes1_attributes = { nodes1_attributes = {
'input': {'kind': 'op', 'op': 'AnyOp'}, 'input': {'kind': 'op', 'op': 'AnyOp'},
@ -247,9 +247,9 @@ class TestQuantizeLinearResolver(unittest.TestCase):
self.assertTrue(flag, resp) self.assertTrue(flag, resp)
@generator class TestQuantizeWithAxis():
class TestQuantizeWithAxis(unittest.TestCase): @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value,target_shape, in_low, in_high, out_low, out_high, axis",
@generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32),
np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]),
np.array([-2., -3., -4., -5.]), np.array([253., 252., 251., 250.]), np.array([-2., -3., -4., -5.]), np.array([253., 252., 251., 250.]),
0, 255, 2), 0, 255, 2),
@ -366,4 +366,4 @@ class TestQuantizeWithAxis(unittest.TestCase):
QuantizeLinearResolver().find_and_replace_pattern(graph) QuantizeLinearResolver().find_and_replace_pattern(graph)
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -31,9 +30,8 @@ graph_edges_sizes = [
] ]
@generator class TestComplexOp():
class TestComplexOp(unittest.TestCase): @pytest.mark.parametrize("input_shape, output_shape",[
@generate(*[
([1, 260, 100, 150], [1, 260, 100, 150, 2]), ([1, 260, 100, 150], [1, 260, 100, 150, 2]),
([1, 260, 100], [1, 260, 100, 2]), ([1, 260, 100], [1, 260, 100, 2]),
([5, 14, 300, 40], [5, 14, 300, 40, 2]), ([5, 14, 300, 40], [5, 14, 300, 40, 2]),
@ -52,5 +50,5 @@ class TestComplexOp(unittest.TestCase):
msg = "Complex operation infer failed for case: expected_shape={}, actual_shape={}" msg = "Complex operation infer failed for case: expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)),\
msg.format(output_shape, graph.node['complex_data']['shape'])) msg.format(output_shape, graph.node['complex_data']['shape'])

View File

@ -1,10 +1,8 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import pytest
import unittest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.ExtractImagePatches import ExtractImagePatches from openvino.tools.mo.ops.ExtractImagePatches import ExtractImagePatches
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -26,9 +24,8 @@ edges = [
('EIP_data', 'output'), ('EIP_data', 'output'),
] ]
@generator class TestExtractImagePatchesPartialInfer():
class TestExtractImagePatchesPartialInfer(unittest.TestCase): @pytest.mark.parametrize("input_shape, sizes, strides, rates, auto_pad, layout, output_shape",[
@generate(*[
([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 2, 2, 27]),
([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 2, 2, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 2, 2, 1], 'valid', 'NHWC', [1, 2, 2, 27]),
([1, 10, 10, 3], [1, 4, 4, 1], [1, 8, 8, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 1, 1, 48]), ([1, 10, 10, 3], [1, 4, 4, 1], [1, 8, 8, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 1, 1, 48]),
@ -65,4 +62,4 @@ class TestExtractImagePatchesPartialInfer(unittest.TestCase):
eip_node = Node(graph, 'EIP') eip_node = Node(graph, 'EIP')
ExtractImagePatches.infer(eip_node) ExtractImagePatches.infer(eip_node)
self.assertTrue(np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape)) assert np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape)

View File

@ -1,11 +1,10 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
import numpy.testing as npt import numpy.testing as npt
from generator import generate, generator
from openvino.tools.mo.ops.If import If from openvino.tools.mo.ops.If import If
from openvino.tools.mo.ops.elementwise import Add, Mul from openvino.tools.mo.ops.elementwise import Add, Mul
@ -22,9 +21,8 @@ from unit_tests.utils.graph import regular_op_with_empty_data, connect, result,
empty_data empty_data
@generator class TestIf():
class TestIf(unittest.TestCase): @pytest.mark.parametrize("cond, output_port_0_shape, output_port_1_shape",[
@generate(*[
(np.array([True], dtype=bool), shape_array([3]), shape_array([3])), (np.array([True], dtype=bool), shape_array([3]), shape_array([3])),
(np.array([False], dtype=bool), shape_array([3]), shape_array([2])), (np.array([False], dtype=bool), shape_array([3]), shape_array([2])),
(shape_array(dynamic_dimension_value), shape_array([3]), shape_array([dynamic_dimension_value])), (shape_array(dynamic_dimension_value), shape_array([3]), shape_array([dynamic_dimension_value])),
@ -94,9 +92,9 @@ class TestIf(unittest.TestCase):
graph.stage = 'middle' graph.stage = 'middle'
partial_infer(graph) partial_infer(graph)
if_node = Node(graph, 'if') if_node = Node(graph, 'if')
self.assertTrue(strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape)) assert strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape)
# shape of the "then" branch is [3] and shape of the "else" branch is [2], so the output shape is "[dynamic]" # shape of the "then" branch is [3] and shape of the "else" branch is [2], so the output shape is "[dynamic]"
self.assertTrue(strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape)) assert strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape)
def test_fake_results(self): def test_fake_results(self):
then_graph_nodes = {**valued_const_with_data('fake_const', int64_array(0)), then_graph_nodes = {**valued_const_with_data('fake_const', int64_array(0)),

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.MatMul import MatMul from openvino.tools.mo.ops.MatMul import MatMul
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value
@ -12,8 +11,7 @@ from openvino.tools.mo.graph.graph import Node
from unit_tests.utils.graph import build_graph_with_attrs from unit_tests.utils.graph import build_graph_with_attrs
@generator class TestMatMul():
class TestMatMul(unittest.TestCase):
nodes = [ nodes = [
('A', {'type': 'Parameter', 'kind': 'op'}), ('A', {'type': 'Parameter', 'kind': 'op'}),
('A_d', {'kind': 'data'}), ('A_d', {'kind': 'data'}),
@ -32,7 +30,7 @@ class TestMatMul(unittest.TestCase):
('mat_mul_d', 'op_output'), ('mat_mul_d', 'op_output'),
] ]
@generate(*[ @pytest.mark.parametrize("A_shape, B_shape, C_shape, transpose_a, transpose_b",[
([1024], [1024, 1000], [1000], False, False), ([1024], [1024, 1000], [1000], False, False),
([dynamic_dimension_value], [1024, 1000], [1000], False, False), ([dynamic_dimension_value], [1024, 1000], [1000], False, False),
([1024], [dynamic_dimension_value, 1000], [1000], False, False), ([1024], [dynamic_dimension_value, 1000], [1000], False, False),
@ -65,11 +63,11 @@ class TestMatMul(unittest.TestCase):
msg = "MatMul infer failed for case: A_shape={}, B_shape={}, transpose_a={}, transpose_b={} " \ msg = "MatMul infer failed for case: A_shape={}, B_shape={}, transpose_a={}, transpose_b={} " \
"expected_shape={}, actual_shape={}" "expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)), assert np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)),\
msg.format(A_shape, B_shape, transpose_a, transpose_b, C_shape, msg.format(A_shape, B_shape, transpose_a, transpose_b, C_shape,
graph.node['mat_mul_d']['shape'])) graph.node['mat_mul_d']['shape'])
@generate(*[ @pytest.mark.parametrize("A_shape, B_shape",[
(None, [1024, 1000]), (None, [1024, 1000]),
(1, [1024, 1000]), (1, [1024, 1000]),
([], [1024, 1000]), ([], [1024, 1000]),
@ -84,4 +82,5 @@ class TestMatMul(unittest.TestCase):
]) ])
node = Node(graph, 'mat_mul') node = Node(graph, 'mat_mul')
self.assertRaises(AssertionError, MatMul.infer, node) with pytest.raises(AssertionError):
MatMul.infer(node)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.MatMul import MatMul, transpose from openvino.tools.mo.ops.MatMul import MatMul, transpose
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -32,9 +31,8 @@ graph_edges=[
] ]
@generator class TestMatMulValuePropagation():
class TestMatMulValuePropagation(unittest.TestCase): @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, transpose_a, transpose_b",[
@generate(*[
([16, 3], np.arange(-5, -5 + 16 * 3).reshape((16, 3)), ([16, 3], np.arange(-5, -5 + 16 * 3).reshape((16, 3)),
[3, 5], np.arange(0, 3 * 5).reshape((3, 5)), [3, 5], np.arange(0, 3 * 5).reshape((3, 5)),
False, False), False, False),
@ -91,4 +89,4 @@ class TestMatMulValuePropagation(unittest.TestCase):
node_data_shape = node_data.shape node_data_shape = node_data.shape
ref_data_shape = ref_data.shape ref_data_shape = ref_data.shape
msg = "Value propagation for 'matmul' node is not correct." msg = "Value propagation for 'matmul' node is not correct."
self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.ONNXResize11 import ONNXResize11Op from openvino.tools.mo.ops.ONNXResize11 import ONNXResize11Op
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -68,9 +67,8 @@ graph_edges_scales = [
] ]
@generator class TestONNXResize11Op():
class TestONNXResize11Op(unittest.TestCase): @pytest.mark.parametrize("input_shape, output_shape, sizes, scales",[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]),
@generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]),
([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]),
([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]),
([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]),
@ -95,10 +93,11 @@ class TestONNXResize11Op(unittest.TestCase):
msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])
@generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), @pytest.mark.parametrize("input_shape, output_shape, scales",
[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]),
([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]),
([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]),
([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]),
@ -121,10 +120,11 @@ class TestONNXResize11Op(unittest.TestCase):
msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\
msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])
@generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), @pytest.mark.parametrize("input_shape, output_shape, sizes, scales",
[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]),
([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]),
([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]),
([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]),
@ -155,10 +155,11 @@ class TestONNXResize11Op(unittest.TestCase):
msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])
@generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), @pytest.mark.parametrize("input_shape, output_shape, scales",
[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]),
([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]),
([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]),
([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]),
@ -187,5 +188,5 @@ class TestONNXResize11Op(unittest.TestCase):
msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\
msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generate, generator
from openvino.tools.mo.ops.ReduceOps import reduce_infer from openvino.tools.mo.ops.ReduceOps import reduce_infer
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, is_fully_defined from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, is_fully_defined
@ -21,9 +20,8 @@ nodes_attributes = {
} }
@generator class TestReduceLpTest():
class ReduceLpTest(unittest.TestCase): @pytest.mark.parametrize("shape, axes, keepdims, p",[
@generate(*[
([3, 2, 2], [0], True, 1), ([3, 2, 2], [0], True, 1),
([3, 2, 2], [0], True, 2), ([3, 2, 2], [0], True, 2),
([3, 2, 2], [1], True, 2), ([3, 2, 2], [1], True, 2),
@ -53,9 +51,9 @@ class ReduceLpTest(unittest.TestCase):
reduce_node = Node(graph, 'reduce_lp') reduce_node = Node(graph, 'reduce_lp')
reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_node.op = reduce_node.type = 'ReduceL' + str(p)
reduce_infer(reduce_node) reduce_infer(reduce_node)
self.assertTrue(np.array_equal(reduce_node.out_port(0).data.get_value(), reduced)) assert np.array_equal(reduce_node.out_port(0).data.get_value(), reduced)
@generate(*[ @pytest.mark.parametrize("shape, axes, keepdims, p",[
([3, 2, 2], [0], True, 1), ([3, 2, 2], [0], True, 1),
([3, 2, 2], [2], False, 2), ([3, 2, 2], [2], False, 2),
([3, 2, 2], [0, 2], False, 2), ([3, 2, 2], [0, 2], False, 2),
@ -86,4 +84,4 @@ class ReduceLpTest(unittest.TestCase):
reduce_node = Node(graph, 'reduce_lp') reduce_node = Node(graph, 'reduce_lp')
reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_node.op = reduce_node.type = 'ReduceL' + str(p)
reduce_infer(reduce_node) reduce_infer(reduce_node)
self.assertTrue(strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined)) assert strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, undefined_shape_of_rank from openvino.tools.mo.front.common.partial_infer.utils import int64_array, undefined_shape_of_rank
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -13,31 +12,30 @@ from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_
shaped_data shaped_data
@generator class TestBroadcastTest():
class BroadcastTest(unittest.TestCase): @pytest.mark.parametrize("data, target_shape, axes_mapping, mode, ref_out, test_raising",[
@generate(*[ ([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]], False),
([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), ([1], [3, 3], None, 'numpy', None, False),
([1], [3, 3], None, 'numpy'),
# shape broadcasting # shape broadcasting
([1], [1, 2], [0], 'explicit'), ([1], [1, 2], [0], 'explicit', None, False),
([1], [1, 2], [-2], 'explicit'), ([1], [1, 2], [-2], 'explicit', None, False),
([1, 7], [5, 1, 7, 3], [1, 2], 'explicit'), ([1, 7], [5, 1, 7, 3], [1, 2], 'explicit', None, False),
([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit'), ([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit', None, False),
([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit'), ([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit', None, False),
# value broadcasting # value broadcasting
([1], [1, 2], [0], 'explicit', [[1, 1]]), ([1], [1, 2], [0], 'explicit', [[1, 1]], False),
([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) ([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2)
([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) ([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2)
([[[9, 5, 7]], [[9, 5, 7]]], [2, 2, 1, 3], [1, 2, 3], 'explicit', # in_shape (2, 1, 3) ([[[9, 5, 7]], [[9, 5, 7]]], [2, 2, 1, 3], [1, 2, 3], 'explicit', # in_shape (2, 1, 3)
[[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]]), # ref_out_shape (2, 2, 1, 3) [[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]], False), # ref_out_shape (2, 2, 1, 3)
([[[9, 5, 7]], [[3, 4, 8]]], [2, 1, 3, 3], [0, 1, 2], 'explicit', # in_shape (2, 1, 3) ([[[9, 5, 7]], [[3, 4, 8]]], [2, 1, 3, 3], [0, 1, 2], 'explicit', # in_shape (2, 1, 3)
[[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]]), # ref_out_shape (2, 1, 3, 3) [[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]], False), # ref_out_shape (2, 1, 3, 3)
# negative tests # negative tests
([1], [2, 2], [0], 'explicit', None, True), ([1], [2, 2], [0], 'explicit', None, True),
@ -45,7 +43,7 @@ class BroadcastTest(unittest.TestCase):
([1, 7], [5, 2, 7, 3], [2, 1], 'explicit', None, True), ([1, 7], [5, 2, 7, 3], [2, 1], 'explicit', None, True),
([1, 7], [5, 2, 7, 3], [-3, -2], 'explicit', None, True), ([1, 7], [5, 2, 7, 3], [-3, -2], 'explicit', None, True),
]) ])
def test_broadcast(self, data, target_shape, axes_mapping=None, mode='numpy', ref_out=None, test_raising=False): def test_broadcast(self, data, target_shape, axes_mapping, mode, ref_out, test_raising):
if ref_out is not None: if ref_out is not None:
input = valued_const_with_data('data', int64_array(data)) input = valued_const_with_data('data', int64_array(data))
else: else:
@ -68,25 +66,26 @@ class BroadcastTest(unittest.TestCase):
broadcast_node = Node(graph, 'broadcast') broadcast_node = Node(graph, 'broadcast')
if test_raising: if test_raising:
self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) with pytest.raises(AssertionError):
Broadcast.infer(broadcast_node)
return return
Broadcast.infer(broadcast_node) Broadcast.infer(broadcast_node)
if ref_out is not None: if ref_out is not None:
self.assertTrue(np.array_equal(broadcast_node.out_node().value, np.array(ref_out))) assert np.array_equal(broadcast_node.out_node().value, np.array(ref_out))
else: else:
self.assertTrue(np.array_equal(broadcast_node.out_node().shape, np.array(target_shape))) assert np.array_equal(broadcast_node.out_node().shape, np.array(target_shape))
@generate(*[ @pytest.mark.parametrize("data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising",[
([1], [3], [0], 'explicit', undefined_shape_of_rank(3)), ([1], [3], [0], 'explicit', undefined_shape_of_rank(3), False),
([1], [3], None, 'numpy', undefined_shape_of_rank(3)), ([1], [3], None, 'numpy', undefined_shape_of_rank(3), False),
([1], [3], None, 'bidirectional', undefined_shape_of_rank(3)), ([1], [3], None, 'bidirectional', undefined_shape_of_rank(3),False),
([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4)), ([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4), False),
([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3)), ([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3),False),
([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2)), ([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2), False),
([1, 1], [2, 1], None, 'numpy', None, True), ([1, 1], [2, 1], None, 'numpy', None, True),
]) ])
def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping=None, mode='numpy', ref_out_shape=None, test_raising=False): def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising):
nodes = { nodes = {
**shaped_data('data', int64_array(data)), **shaped_data('data', int64_array(data)),
**shaped_data('target_shape', int64_array(target_shape_shape)), **shaped_data('target_shape', int64_array(target_shape_shape)),
@ -105,8 +104,9 @@ class BroadcastTest(unittest.TestCase):
broadcast_node = Node(graph, 'broadcast') broadcast_node = Node(graph, 'broadcast')
if test_raising: if test_raising:
self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) with pytest.raises(AssertionError):
Broadcast.infer(broadcast_node)
return return
Broadcast.infer(broadcast_node) Broadcast.infer(broadcast_node)
self.assertTrue(np.array_equal(broadcast_node.out_node().shape, ref_out_shape)) assert np.array_equal(broadcast_node.out_node().shape, ref_out_shape)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.Cast import Cast from openvino.tools.mo.ops.Cast import Cast
from openvino.tools.mo.middle.passes.convert_data_type import packed_U4, packed_I4 from openvino.tools.mo.middle.passes.convert_data_type import packed_U4, packed_I4
@ -19,8 +18,7 @@ nodes = lambda value, dst_type: {
} }
@generator class TestCastTest():
class CastTest(unittest.TestCase):
""" """
Example of checking: Example of checking:
7 == 0111, padded to 0111 0000, results in 112 7 == 0111, padded to 0111 0000, results in 112
@ -29,7 +27,7 @@ class CastTest(unittest.TestCase):
-8 == 1000, padded to 1000 0000, results in 128 -8 == 1000, padded to 1000 0000, results in 128
""" """
@generate(*[ @pytest.mark.parametrize("value, expected, custom_dtype",[
([0], [0], packed_U4), ([0], [0], packed_U4),
([1], [16], packed_U4), ([1], [16], packed_U4),
([2], [32], packed_U4), ([2], [32], packed_U4),
@ -110,4 +108,4 @@ class CastTest(unittest.TestCase):
'value': expected}}) 'value': expected}})
(flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp

View File

@ -1,18 +1,16 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.dft import FFTBase from openvino.tools.mo.ops.dft import FFTBase
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@generator class TestDFTSignalSizeCanonicalizationTest():
class DFTSignalSizeCanonicalizationTest(unittest.TestCase): @pytest.mark.parametrize("signal_size, axes, input_shape, expected_result",[
@generate(*[
(int64_array([-1, 77]), int64_array([1, 2]), int64_array([2, 180, 180, 2]), int64_array([180, 77])), (int64_array([-1, 77]), int64_array([1, 2]), int64_array([2, 180, 180, 2]), int64_array([180, 77])),
(int64_array([390, 87]), int64_array([2, 0]), int64_array([2, 180, 180, 2]), int64_array([390, 87])), (int64_array([390, 87]), int64_array([2, 0]), int64_array([2, 180, 180, 2]), int64_array([390, 87])),
(int64_array([600, -1, 40]), (int64_array([600, -1, 40]),
@ -38,4 +36,4 @@ class DFTSignalSizeCanonicalizationTest(unittest.TestCase):
]) ])
def test_canonicalization(self, signal_size, axes, input_shape, expected_result): def test_canonicalization(self, signal_size, axes, input_shape, expected_result):
canonicalized_signal_size = FFTBase.canonicalize_signal_size(signal_size, axes, input_shape) canonicalized_signal_size = FFTBase.canonicalize_signal_size(signal_size, axes, input_shape)
self.assertTrue(np.array_equal(canonicalized_signal_size, expected_result)) assert np.array_equal(canonicalized_signal_size, expected_result)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.elementwise import Div from openvino.tools.mo.ops.elementwise import Div
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -32,9 +31,8 @@ graph_edges = [
] ]
@generator class TestDivValuePropagation():
class TestDivValuePropagation(unittest.TestCase): @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, elem_type",[
@generate(*[
([2, 3], np.array([[1, 4, -6], [0, -16, 45]], dtype=np.int64), ([2, 3], np.array([[1, 4, -6], [0, -16, 45]], dtype=np.int64),
[2, 3], np.array([[1, 2, -4], [1, -8, -5]], dtype=np.int64), [2, 3], np.array([[1, 2, -4], [1, -8, -5]], dtype=np.int64),
np.int64), np.int64),
@ -80,4 +78,4 @@ class TestDivValuePropagation(unittest.TestCase):
node_data_shape = node_data.shape node_data_shape = node_data.shape
ref_data_shape = ref_data.shape ref_data_shape = ref_data.shape
msg = "Value propagation for 'div' node is not correct." msg = "Value propagation for 'div' node is not correct."
self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.einsum import Einsum from openvino.tools.mo.ops.einsum import Einsum
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -35,9 +34,8 @@ def create_einsum_graph(input_shapes: list, equation: str) -> Graph:
return graph return graph
@generator class TestEinsum():
class TestEinsum(unittest.TestCase): @pytest.mark.parametrize("input_shapes, equation, ref_output_shape",[
@generate(*[
# dot product # dot product
([int64_array([10]), int64_array([10])], "i,i->", int64_array([])), ([int64_array([10]), int64_array([10])], "i,i->", int64_array([])),
# matrix multiplication # matrix multiplication
@ -74,22 +72,23 @@ class TestEinsum(unittest.TestCase):
# get the result # get the result
res_output_shape = graph.node['einsum_node_d']['shape'] res_output_shape = graph.node['einsum_node_d']['shape']
self.assertTrue(np.array_equal(ref_output_shape, res_output_shape), assert np.array_equal(ref_output_shape, res_output_shape),\
'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape)) 'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape)
@generate(*[ @pytest.mark.parametrize("input_shapes, equation, ref_output_shape", [
# incorrect subscript numbers or inputs # incorrect subscript numbers or inputs
([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None), ([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None),
# invalid labels # invalid labels
([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None), ([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None),
# incompatible shapes # incompatible shapes
([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None), ([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None),
# not broadcastable shapes # not broadcastable shapes
([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None), ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None),
# missed ellipsis # missed ellipsis
([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None), ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None),
]) ])
def test_invalid_cases(self, input_shapes, equation, ref_output_shape): def test_invalid_cases(self, input_shapes, equation, ref_output_shape):
graph = create_einsum_graph(input_shapes, equation) graph = create_einsum_graph(input_shapes, equation)
einsum_node = Node(graph, 'einsum_node') einsum_node = Node(graph, 'einsum_node')
self.assertRaises(AssertionError, Einsum.infer, einsum_node) with pytest.raises(AssertionError):
Einsum.infer(einsum_node)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -28,9 +27,8 @@ nodes_attributes = {
} }
} }
@generator class TestExpandDimsOp():
class ExpandDimsOp(unittest.TestCase): @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, 224, 224]),
@generate(*[(0, [1, 2, 3, 224, 224]),
(1, [2, 1, 3, 224, 224]), (1, [2, 1, 3, 224, 224]),
(2, [2, 3, 1, 224, 224]), (2, [2, 3, 1, 224, 224]),
(3, [2, 3, 224, 1, 224]), (3, [2, 3, 224, 1, 224]),
@ -45,12 +43,11 @@ class ExpandDimsOp(unittest.TestCase):
ExpandDims.infer(expand_dims_node) ExpandDims.infer(expand_dims_node)
self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))
@generator class TestExpandDimsOpDynamicDims():
class ExpandDimsOpDynamicDims(unittest.TestCase): @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, dynamic_dimension_value, 224]),
@generate(*[(0, [1, 2, 3, dynamic_dimension_value, 224]),
(1, [2, 1, 3, dynamic_dimension_value, 224]), (1, [2, 1, 3, dynamic_dimension_value, 224]),
(2, [2, 3, 1, dynamic_dimension_value, 224]), (2, [2, 3, 1, dynamic_dimension_value, 224]),
(3, [2, 3, dynamic_dimension_value, 1, 224]), (3, [2, 3, dynamic_dimension_value, 1, 224]),
@ -66,12 +63,11 @@ class ExpandDimsOpDynamicDims(unittest.TestCase):
ExpandDims.infer(expand_dims_node) ExpandDims.infer(expand_dims_node)
self.assertTrue(strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape))) assert strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape))
@generator class TestExpandDimsOpValueInfer():
class ExpandDimsOpValueInfer(unittest.TestCase): @pytest.mark.parametrize("axis, in_shape, ref_out_shape",[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]),
@generate(*[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]),
(1, [2, 3, 224, 224], [2, 1, 3, 224, 224]), (1, [2, 3, 224, 224], [2, 1, 3, 224, 224]),
(2, [2, 3, 224, 224], [2, 3, 1, 224, 224]), (2, [2, 3, 224, 224], [2, 3, 1, 224, 224]),
(3, [2, 3, 224, 224], [2, 3, 224, 1, 224]), (3, [2, 3, 224, 224], [2, 3, 224, 1, 224]),
@ -88,5 +84,5 @@ class ExpandDimsOpValueInfer(unittest.TestCase):
ExpandDims.infer(expand_dims_node) ExpandDims.infer(expand_dims_node)
self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))
self.assertTrue(np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape)))) assert np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape)))

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.eye import Eye from openvino.tools.mo.ops.eye import Eye
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -50,17 +49,16 @@ graph_edges_sizes = [
] ]
@generator class TestComplexOp():
class TestComplexOp(unittest.TestCase): @pytest.mark.parametrize("input_shape, output_shape, num_rows, num_cols, batch_shape",[
@generate(*[ ([], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]),
([], [dynamic_dimension_value, dynamic_dimension_value]), ([1], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]),
([1], [dynamic_dimension_value, dynamic_dimension_value]),
([1], [2, dynamic_dimension_value, dynamic_dimension_value], None, None, [2]), ([1], [2, dynamic_dimension_value, dynamic_dimension_value], None, None, [2]),
([1], [2, 3, dynamic_dimension_value], 3, None, [2]), ([1], [2, 3, dynamic_dimension_value], 3, None, [2]),
([1], [2, dynamic_dimension_value, 4], None, 4, [2]), ([1], [2, dynamic_dimension_value, 4], None, 4, [2]),
([1], [2, 3, 4], [3], [4], [2]) ([1], [2, 3, 4], [3], [4], [2])
]) ])
def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows=None, num_cols=None, batch_shape=[]): def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows, num_cols, batch_shape):
graph = build_graph_with_attrs(nodes_with_attrs=graph_node_attrs_sizes, graph = build_graph_with_attrs(nodes_with_attrs=graph_node_attrs_sizes,
edges_with_attrs=graph_edges_sizes, edges_with_attrs=graph_edges_sizes,
update_nodes_attributes=[ update_nodes_attributes=[
@ -75,8 +73,8 @@ class TestComplexOp(unittest.TestCase):
msg = "Eye operation infer failed for case: expected_shape={}, actual_shape={}" msg = "Eye operation infer failed for case: expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['eye_op_data']['shape'], output_shape), assert np.array_equal(graph.node['eye_op_data']['shape'], output_shape),\
msg.format(output_shape, graph.node['eye_op_data']['shape'])) msg.format(output_shape, graph.node['eye_op_data']['shape'])
def test_value_inference(self): def test_value_inference(self):
graph_node_attrs_sizes = { graph_node_attrs_sizes = {
@ -103,5 +101,5 @@ class TestComplexOp(unittest.TestCase):
msg = "Eye operation infer failed for case: expected_value={}, actual_value={}" msg = "Eye operation infer failed for case: expected_value={}, actual_value={}"
self.assertTrue(np.array_equal(graph.node['eye_op_d']['value'], output_value), assert np.array_equal(graph.node['eye_op_d']['value'], output_value),\
msg.format(output_value, graph.node['eye_op_d']['value'])) msg.format(output_value, graph.node['eye_op_d']['value'])

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.gatherelements import GatherElements from openvino.tools.mo.ops.gatherelements import GatherElements
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, dynamic_dimension from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, dynamic_dimension
@ -15,9 +14,8 @@ from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, resu
dyn = dynamic_dimension dyn = dynamic_dimension
@generator class TestGatherElementsInferTest():
class GatherElementsInferTest(unittest.TestCase): @pytest.mark.parametrize("data, indices, axis, ref_res",[
@generate(*[
([[1, 2], ([[1, 2],
[3, 4]], [3, 4]],
[[0, 1], [[0, 1],
@ -96,11 +94,11 @@ class GatherElementsInferTest(unittest.TestCase):
GatherElements.infer(gather_el_node) GatherElements.infer(gather_el_node)
res_output_shape = gather_el_node.out_node().shape res_output_shape = gather_el_node.out_node().shape
self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) assert np.array_equal(int64_array(ref_res).shape, res_output_shape)
res_output_value = gather_el_node.out_node().value res_output_value = gather_el_node.out_node().value
if res_output_value is not None: if res_output_value is not None:
self.assertTrue(np.array_equal(int64_array(ref_res), res_output_value)) assert np.array_equal(int64_array(ref_res), res_output_value)
def check_shape_infer(self, data_shape, indices_shape, axis, ref): def check_shape_infer(self, data_shape, indices_shape, axis, ref):
nodes = { nodes = {
@ -121,7 +119,7 @@ class GatherElementsInferTest(unittest.TestCase):
GatherElements.infer(gather_el_node) GatherElements.infer(gather_el_node)
res_output_shape = gather_el_node.out_node().shape res_output_shape = gather_el_node.out_node().shape
self.assertTrue(strict_compare_tensors(res_output_shape, ref)) assert strict_compare_tensors(res_output_shape, ref)
def test_shape_infer_1(self): def test_shape_infer_1(self):
self.check_shape_infer(data_shape=[3], indices_shape=[100], ref=[100], axis=0) self.check_shape_infer(data_shape=[3], indices_shape=[100], ref=[100], axis=0)
@ -165,13 +163,13 @@ class GatherElementsInferTest(unittest.TestCase):
# negative tests # negative tests
def test_negative_shape_infer_ranks_differ(self): def test_negative_shape_infer_ranks_differ(self):
self.assertRaises(AssertionError, self.check_shape_infer, with pytest.raises(AssertionError):
data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2) self.check_shape_infer(data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2)
def test_negative_shape_infer_axis_out_of_bound(self): def test_negative_shape_infer_axis_out_of_bound(self):
self.assertRaises(AssertionError, self.check_shape_infer, with pytest.raises(AssertionError):
data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20) self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20)
def test_negative_shape_infer_inconsistent_shapes(self): def test_negative_shape_infer_inconsistent_shapes(self):
self.assertRaises(Error, self.check_shape_infer, with pytest.raises(Error):
data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2) self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.interpolate import Interpolate from openvino.tools.mo.ops.interpolate import Interpolate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array
@ -72,9 +71,9 @@ graph_edges = [
] ]
@generator class TestInterpolateOp():
class TestInterpolateOp(unittest.TestCase): @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes",
@generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]),
([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600],
[8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]),
([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028],
@ -114,11 +113,12 @@ class TestInterpolateOp(unittest.TestCase):
msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \
" expected_shape={}, actual_shape={}" " expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape,
graph.node['interpolate_data']['shape'])) graph.node['interpolate_data']['shape'])
@generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes",
[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]),
([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600],
[8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]),
([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028],
@ -165,11 +165,12 @@ class TestInterpolateOp(unittest.TestCase):
msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \
" expected_shape={}, actual_shape={}" " expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape,
graph.node['interpolate_data']['shape'])) graph.node['interpolate_data']['shape'])
@generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales",
[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]),
([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600],
[8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]),
([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028],
@ -212,11 +213,12 @@ class TestInterpolateOp(unittest.TestCase):
msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \
" expected_shape={}, actual_shape={}" " expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, pads_begin, pads_end, output_shape, msg.format(sizes, scales, pads_begin, pads_end, output_shape,
graph.node['interpolate_data']['shape'])) graph.node['interpolate_data']['shape'])
@generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales",
[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]),
([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600],
[8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]),
([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028],
@ -262,6 +264,6 @@ class TestInterpolateOp(unittest.TestCase):
msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \
" expected_shape={}, actual_shape={}" " expected_shape={}, actual_shape={}"
self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\
msg.format(sizes, scales, pads_begin, pads_end, output_shape, msg.format(sizes, scales, pads_begin, pads_end, output_shape,
graph.node['interpolate_data']['shape'])) graph.node['interpolate_data']['shape'])

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.one_hot import OneHot from openvino.tools.mo.ops.one_hot import OneHot
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float_array from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float_array
@ -32,29 +31,28 @@ edges = [
] ]
@generator class TestOneHotInfer():
class TestOneHotInfer(unittest.TestCase): @pytest.mark.parametrize("input_value, exp_value, axis",[
@generate(*[
# 0d input # 0d input
(1, [0, 1, 0, 0]), (1, [0, 1, 0, 0], -1),
# 1d input # 1d input
([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]]), ([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]], -1),
# 2D input # 2D input
([[1, 2], [3, 4]], [[[0, 1, 0, 0], [0, 0, 1, 0]], ([[1, 2], [3, 4]], [[[0, 1, 0, 0], [0, 0, 1, 0]],
[[0, 0, 0, 1], [0, 0, 0, 0]]]), [[0, 0, 0, 1], [0, 0, 0, 0]]], -1),
# 3d input # 3d input
([[[0, 2], [1, 2]], [[2, 1], [3, 0]]], ([[[0, 2], [1, 2]], [[2, 1], [3, 0]]],
[[[[1, 0, 0, 0], [0, 0, 1, 0]], [[0, 1, 0, 0], [0, 0, 1, 0]]], [[[[1, 0, 0, 0], [0, 0, 1, 0]], [[0, 1, 0, 0], [0, 0, 1, 0]]],
[[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]]), [[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]], -1),
# 1d input with negative indices # 1d input with negative indices
([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]]), ([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]], -1),
# check if axis is neither 0 nor -1 # check if axis is neither 0 nor -1
([[1, 2], [3, 4]], [[[0, 0], [1, 0], [0, 1], [0, 0]], ([[1, 2], [3, 4]], [[[0, 0], [1, 0], [0, 1], [0, 0]],
[[0, 0], [0, 0], [0, 0], [1, 0]]], 1) [[0, 0], [0, 0], [0, 0], [1, 0]]], 1)
]) ])
def test_infer(self, input_value, exp_value, axis=-1): def test_infer(self, input_value, exp_value, axis):
graph = build_graph(generate_nodes(int64_array(input_value), axis), edges) graph = build_graph(generate_nodes(int64_array(input_value), axis), edges)
onehot_node = Node(graph, 'one_hot') onehot_node = Node(graph, 'one_hot')
OneHot.infer(onehot_node) OneHot.infer(onehot_node)
res_value = graph.node['one_hot_d']['value'] res_value = graph.node['one_hot_d']['value']
self.assertTrue(np.array_equal(exp_value, int64_array(res_value))) assert np.array_equal(exp_value, int64_array(res_value))

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generate, generator
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -47,9 +46,8 @@ nodes_attributes = {
} }
@generator class TestReshapeShapeInfer():
class TestReshapeShapeInfer(unittest.TestCase): @pytest.mark.parametrize("input_value, input_shape, output_shape, ref_value, ref_shape",[
@generate(*[
(None, shape_array([1, 100, 4]), shape_array([-1, 25]), None, [16, 25]), (None, shape_array([1, 100, 4]), shape_array([-1, 25]), None, [16, 25]),
(None, shape_array([5, 100, 4]), shape_array([0, -1, 25]), None, [5, 16, 25]), (None, shape_array([5, 100, 4]), shape_array([0, -1, 25]), None, [5, 16, 25]),
(None, shape_array([5, dynamic_dimension_value, 4]), shape_array([4, -1, 5]), None, (None, shape_array([5, dynamic_dimension_value, 4]), shape_array([4, -1, 5]), None,
@ -89,5 +87,5 @@ class TestReshapeShapeInfer(unittest.TestCase):
node = Node(graph, 'reshape') node = Node(graph, 'reshape')
Reshape.infer(node) Reshape.infer(node)
if ref_value is not None: if ref_value is not None:
self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value))) assert strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value))
self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape))) assert strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape))

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.scatter import ScatterElementsUpdate, ScatterUpdate from openvino.tools.mo.ops.scatter import ScatterElementsUpdate, ScatterUpdate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value
@ -12,9 +11,8 @@ from openvino.tools.mo.graph.graph import Node
from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, valued_const_with_data from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, valued_const_with_data
@generator class TestScatterElementsInferTest():
class ScatterElementsInferTest(unittest.TestCase): @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[
@generate(*[
([[0.0, 0.0, 0.0], ([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]], [0.0, 0.0, 0.0]],
@ -96,15 +94,14 @@ class ScatterElementsInferTest(unittest.TestCase):
ScatterElementsUpdate.infer(scatter_el_node) ScatterElementsUpdate.infer(scatter_el_node)
res_output_shape = scatter_el_node.out_node().shape res_output_shape = scatter_el_node.out_node().shape
self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) assert np.array_equal(int64_array(ref_res).shape, res_output_shape)
res_output_value = scatter_el_node.out_node().value res_output_value = scatter_el_node.out_node().value
self.assertTrue(np.array_equal(ref_res, res_output_value)) assert np.array_equal(ref_res, res_output_value)
@generator class TestScatterUpdateInferTest():
class ScatterUpdateInferTest(unittest.TestCase): @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[
@generate(*[
([[0.0, 0.0, 0.0], ([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]], [0.0, 0.0, 0.0]],
@ -188,7 +185,7 @@ class ScatterUpdateInferTest(unittest.TestCase):
ScatterUpdate.infer(scatter_update_node) ScatterUpdate.infer(scatter_update_node)
res_output_shape = scatter_update_node.out_node().shape res_output_shape = scatter_update_node.out_node().shape
self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) assert np.array_equal(int64_array(ref_res).shape, res_output_shape)
res_output_value = scatter_update_node.out_node().value res_output_value = scatter_update_node.out_node().value
self.assertTrue(np.array_equal(ref_res, res_output_value)) assert np.array_equal(ref_res, res_output_value)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, \ from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, \
strict_compare_tensors strict_compare_tensors
@ -14,9 +13,8 @@ from unit_tests.utils.graph import build_graph, valued_const_with_data, valued_d
connect, shaped_data, shaped_const_with_data connect, shaped_data, shaped_const_with_data
@generator class TestSliceOp():
class TestSliceOp(unittest.TestCase): @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[
@generate(*[
# standard case # standard case
([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1],
[[5], [3], [6]], [3, 1]), [[5], [3], [6]], [3, 1]),
@ -107,13 +105,12 @@ class TestSliceOp(unittest.TestCase):
Slice.infer(slice_node) Slice.infer(slice_node)
if expected_value is not None: if expected_value is not None:
self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) assert strict_compare_tensors(slice_node.out_node().value, expected_value)
self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) assert strict_compare_tensors(slice_node.out_node().shape, expected_shape)
@generator class TestOvSliceOp():
class TestOvSliceOp(unittest.TestCase): @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[
@generate(*[
# standard case # standard case
([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1],
[[5], [3], [6]], [3, 1]), [[5], [3], [6]], [3, 1]),
@ -204,5 +201,5 @@ class TestOvSliceOp(unittest.TestCase):
OvSlice.infer(slice_node) OvSlice.infer(slice_node)
if expected_value is not None: if expected_value is not None:
self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) assert strict_compare_tensors(slice_node.out_node().value, expected_value)
self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) assert strict_compare_tensors(slice_node.out_node().shape, expected_shape)

View File

@ -4,7 +4,7 @@
import unittest import unittest
import numpy as np import numpy as np
from generator import generator, generate import pytest
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, \ from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, \
dynamic_dimension_value, dynamic_dimension, strict_compare_tensors, mo_array dynamic_dimension_value, dynamic_dimension, strict_compare_tensors, mo_array
@ -248,8 +248,7 @@ class TestAttributedVariadicSplitOp(unittest.TestCase):
self.assertTrue(np.all(node.split_lengths == np.array([2, 13, 10]))) self.assertTrue(np.all(node.split_lengths == np.array([2, 13, 10])))
@generator class TestVariadicSplitOp():
class TestVariadicSplitOp(unittest.TestCase):
nodes = { nodes = {
'input': {'kind': 'op'}, 'input': {'kind': 'op'},
'split_input_data': {'kind': 'data', 'shape': None, 'value': None}, 'split_input_data': {'kind': 'data', 'shape': None, 'value': None},
@ -280,7 +279,7 @@ class TestVariadicSplitOp(unittest.TestCase):
('split_output_2_data', 'output_2'), ('split_output_2_data', 'output_2'),
] ]
@generate(*[int64_array(2), @pytest.mark.parametrize("axis",[int64_array(2),
int64_array([2])]) int64_array([2])])
def test_variadic_split_axis(self, axis): def test_variadic_split_axis(self, axis):
lengths = int64_array([2, 13, 10]) lengths = int64_array([2, 13, 10])
@ -299,9 +298,9 @@ class TestVariadicSplitOp(unittest.TestCase):
VariadicSplit.infer(node) VariadicSplit.infer(node)
ont_nodes_count = len(node.out_edges()) ont_nodes_count = len(node.out_edges())
self.assertTrue(ont_nodes_count == 3) assert ont_nodes_count == 3
for out in range(ont_nodes_count): for out in range(ont_nodes_count):
self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))
def test_variadic_split_value_inference_with_uint32(self): def test_variadic_split_value_inference_with_uint32(self):
axis = int64_array(2) axis = int64_array(2)
@ -329,11 +328,11 @@ class TestVariadicSplitOp(unittest.TestCase):
VariadicSplit.infer(node) VariadicSplit.infer(node)
ont_nodes_count = len(node.out_edges()) ont_nodes_count = len(node.out_edges())
self.assertTrue(ont_nodes_count == 3) assert ont_nodes_count == 3
for out in range(ont_nodes_count): for out in range(ont_nodes_count):
self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))
@generate(*[int64_array([[2], [2]]), @pytest.mark.parametrize("axis",[int64_array([[2], [2]]),
int64_array([2, 2])]) int64_array([2, 2])])
def test_negative_variadic_split_axis(self, axis): def test_negative_variadic_split_axis(self, axis):
lengths = int64_array([2, 13, 10]) lengths = int64_array([2, 13, 10])
@ -352,8 +351,8 @@ class TestVariadicSplitOp(unittest.TestCase):
try: try:
VariadicSplit.infer(node) VariadicSplit.infer(node)
except AssertionError as e: except AssertionError as e:
self.assertTrue(e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], ' assert e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], '\
'but it`s not for node split_op') 'but it`s not for node split_op'
class TestSplitReverseInfer(unittest.TestCase): class TestSplitReverseInfer(unittest.TestCase):

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generate, generator
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -41,9 +40,8 @@ nodes_attributes = {
} }
@generator class TestSqueezeInfer():
class TestSqueezeInfer(unittest.TestCase): @pytest.mark.parametrize("input_value, input_shape, squeeze_dims, ref_value, ref_shape",[
@generate(*[
(None, shape_array([1, 2, 1, 4]), shape_array([2]), None, [1, 2, 4]), (None, shape_array([1, 2, 1, 4]), shape_array([2]), None, [1, 2, 4]),
# allow squeezing dynamic dimensions # allow squeezing dynamic dimensions
(None, shape_array([1, 2, dynamic_dimension_value, 4]), shape_array([2]), None, [1, 2, 4]), (None, shape_array([1, 2, dynamic_dimension_value, 4]), shape_array([2]), None, [1, 2, 4]),
@ -67,10 +65,10 @@ class TestSqueezeInfer(unittest.TestCase):
}) })
node = Node(graph, 'squeeze') node = Node(graph, 'squeeze')
if ref_shape is None: # the test should fail if ref_shape is None: # the test should fail
with self.assertRaises(Error): with pytest.raises(Error):
Squeeze.infer(node) Squeeze.infer(node)
else: else:
Squeeze.infer(node) Squeeze.infer(node)
if ref_value is not None: if ref_value is not None:
self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), ref_value)) assert strict_compare_tensors(node.out_port(0).data.get_value(), ref_value)
self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape)) assert strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape)

View File

@ -3,9 +3,8 @@
import itertools import itertools
import unittest import unittest
import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, strict_compare_tensors, \ from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, strict_compare_tensors, \
dynamic_dimension_value dynamic_dimension_value
@ -19,8 +18,7 @@ from unit_tests.utils.graph import valued_const_with_data, result, regular_op_wi
input_shape = np.array([1, 3, 224, 224]) input_shape = np.array([1, 3, 224, 224])
@generator class TestTransposeOp():
class TestTransposeOp(unittest.TestCase):
nodes_attributes = { nodes_attributes = {
'parameter': { 'parameter': {
'kind': 'op', 'kind': 'op',
@ -71,7 +69,7 @@ class TestTransposeOp(unittest.TestCase):
graph.graph['layout'] = 'NCHW' graph.graph['layout'] = 'NCHW'
return graph return graph
@generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))]) @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))])
def test_transpose_infer_1(self, order): def test_transpose_infer_1(self, order):
graph = self._create_graph_with_transpose(order) graph = self._create_graph_with_transpose(order)
transpose_node = Node(graph, 'transpose') transpose_node = Node(graph, 'transpose')
@ -79,7 +77,7 @@ class TestTransposeOp(unittest.TestCase):
Transpose.infer(transpose_node) Transpose.infer(transpose_node)
ref = [transpose_node.in_node().shape[i] for i in order] ref = [transpose_node.in_node().shape[i] for i in order]
self.assertTrue(np.array_equal(transpose_node.out_node().shape, np.array(ref))) assert np.array_equal(transpose_node.out_node().shape, np.array(ref))
def test_transpose_infer_2(self): def test_transpose_infer_2(self):
order = None order = None
@ -89,22 +87,24 @@ class TestTransposeOp(unittest.TestCase):
Transpose.infer(transpose_node) Transpose.infer(transpose_node)
ref = np.array([x for x in reversed(transpose_node.in_node().shape)]) ref = np.array([x for x in reversed(transpose_node.in_node().shape)])
self.assertTrue(np.array_equal(transpose_node.out_node().shape, ref), assert np.array_equal(transpose_node.out_node().shape, ref),\
"Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref)) "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref)
def test_transpose_infer_neg_1(self): def test_transpose_infer_neg_1(self):
order = np.array([0, 1, 2, 3]) order = np.array([0, 1, 2, 3])
graph = self._create_graph_with_transpose(order) graph = self._create_graph_with_transpose(order)
transpose_node = Node(graph, 'transpose') transpose_node = Node(graph, 'transpose')
transpose_node['reverse_order'] = True transpose_node['reverse_order'] = True
self.assertRaises(AssertionError, Transpose.infer, transpose_node) with pytest.raises(AssertionError):
Transpose.infer(transpose_node)
def test_transpose_infer_neg_2(self): def test_transpose_infer_neg_2(self):
order = None order = None
graph = self._create_graph_with_transpose(order) graph = self._create_graph_with_transpose(order)
transpose_node = Node(graph, 'transpose') transpose_node = Node(graph, 'transpose')
transpose_node['reverse_order'] = False transpose_node['reverse_order'] = False
self.assertRaises(AssertionError, Transpose.infer, transpose_node) with pytest.raises(AssertionError):
Transpose.infer(transpose_node)
dyn = dynamic_dimension_value dyn = dynamic_dimension_value

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value, strict_compare_tensors
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -13,8 +12,7 @@ from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs
from unit_tests.utils.graph import build_graph from unit_tests.utils.graph import build_graph
@generator class TestUnsqueezeOp():
class TestUnsqueezeOp(unittest.TestCase):
nodes_attributes = { nodes_attributes = {
'data_1': { 'data_1': {
'kind': 'data', 'kind': 'data',
@ -39,7 +37,8 @@ class TestUnsqueezeOp(unittest.TestCase):
} }
} }
@generate(*[(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]), @pytest.mark.parametrize("input_shape, unsq_dims, output_shape, ref_uns_dims, input_value, output_value",
[(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]),
int64_array([0, 4]), None, None), int64_array([0, 4]), None, None),
(shape_array([2, 3, 64, 64]), int64_array([-1]), shape_array([2, 3, 64, 64, 1]), int64_array([4]), None, (shape_array([2, 3, 64, 64]), int64_array([-1]), shape_array([2, 3, 64, 64, 1]), int64_array([4]), None,
None), None),
@ -75,7 +74,7 @@ class TestUnsqueezeOp(unittest.TestCase):
Unsqueeze.infer(unsqueeze_node) Unsqueeze.infer(unsqueeze_node)
(flag, resp) = compare_graphs(graph, graph_ref, 'data_2') (flag, resp) = compare_graphs(graph, graph_ref, 'data_2')
self.assertTrue(flag, resp) assert flag, resp
self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape)) assert strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape)
if Node(graph_ref, 'data_2').value is not None: if Node(graph_ref, 'data_2').value is not None:
self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value)) assert strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.ops.upsample import UpsampleOp from openvino.tools.mo.ops.upsample import UpsampleOp
from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors
@ -18,9 +17,8 @@ nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'},
} }
@generator class TestUpsampleOp():
class TestUpsampleOp(unittest.TestCase): @pytest.mark.parametrize("scales, input_shape, expected_shape",[
@generate(*[
(np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])),
(np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])),
(np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])),
@ -46,9 +44,9 @@ class TestUpsampleOp(unittest.TestCase):
upsample_node = Node(graph, 'upsample') upsample_node = Node(graph, 'upsample')
UpsampleOp.upsample_infer(upsample_node) UpsampleOp.upsample_infer(upsample_node)
res_shape = graph.node['node_3']['shape'] res_shape = graph.node['node_3']['shape']
self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) assert strict_compare_tensors(expected_shape, res_shape)
@generate(*[ @pytest.mark.parametrize("scales, input_shape, expected_shape",[
(np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])),
(np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])),
(np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])),
@ -76,4 +74,4 @@ class TestUpsampleOp(unittest.TestCase):
upsample_node = Node(graph, 'upsample') upsample_node = Node(graph, 'upsample')
UpsampleOp.upsample_infer(upsample_node) UpsampleOp.upsample_infer(upsample_node)
res_shape = graph.node['node_3']['shape'] res_shape = graph.node['node_3']['shape']
self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) assert strict_compare_tensors(expected_shape, res_shape)

View File

@ -2,17 +2,14 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import unittest
import pytest
from generator import generator, generate
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
from openvino.tools.mo.pipeline.common import determined_sort, get_fw_tensor_debug_info, get_sorted_outputs from openvino.tools.mo.pipeline.common import determined_sort, get_fw_tensor_debug_info, get_sorted_outputs
from unit_tests.utils.graph import build_graph_with_edge_attrs from unit_tests.utils.graph import build_graph_with_edge_attrs
@generator class TestTopologicalSort():
class TestTopologicalSort(unittest.TestCase): @pytest.mark.parametrize( "edges",[
@generate(
[('A', 'Ad', {'out': 0}), [('A', 'Ad', {'out': 0}),
('Ad', 'B', {'in': 0}), ('Ad', 'B', {'in': 0}),
('B', 'Bd', {'out': 0}), ('B', 'Bd', {'out': 0}),
@ -92,7 +89,7 @@ class TestTopologicalSort(unittest.TestCase):
('Hd', 'J', {'in': 1}), ('Hd', 'J', {'in': 1}),
('Dd', 'F', {'in': 1}), ('Dd', 'F', {'in': 1}),
('Fd', 'H', {'in': 1}), ('Fd', 'H', {'in': 1}),
('Gd', 'H', {'in': 0})] ('Gd', 'H', {'in': 0})]]
) )
def test_determined_topological_sort(self, edges): def test_determined_topological_sort(self, edges):
nodes = {'A': {'type': 'Identity', 'kind': 'op'}, nodes = {'A': {'type': 'Identity', 'kind': 'op'},
@ -123,8 +120,8 @@ class TestTopologicalSort(unittest.TestCase):
outputs = [Node(graph, 'Kd')] outputs = [Node(graph, 'Kd')]
for i in range(100): for i in range(100):
op_order, data_order = determined_sort(outputs) op_order, data_order = determined_sort(outputs)
self.assertListEqual(op_order, ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']) assert op_order == ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
self.assertListEqual(data_order, ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd']) assert data_order == ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd']
class TestGetFWTensorName(unittest.TestCase): class TestGetFWTensorName(unittest.TestCase):

View File

@ -1,19 +1,17 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, strict_compare_tensors from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, strict_compare_tensors
from openvino.tools.mo.utils.broadcasting import uni_directional_broadcasting, uni_directional_shape_broadcasting, \ from openvino.tools.mo.utils.broadcasting import uni_directional_broadcasting, uni_directional_shape_broadcasting, \
bi_directional_shape_broadcasting bi_directional_shape_broadcasting
@generator class TestingBroadcasting():
class TestingBroadcasting(unittest.TestCase): @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]),
@generate(*[([], [20, 30, 10], [20, 30, 10]),
([1], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]),
([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]),
([20, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]),
@ -24,18 +22,18 @@ class TestingBroadcasting(unittest.TestCase):
([5, 10], [1, 10], None), ([5, 10], [1, 10], None),
]) ])
def test_uni_directional_broadcasting(self, input_shape, target_shape, expected_shape): def test_uni_directional_broadcasting(self, input_shape, target_shape, expected_shape):
self.assertTrue(np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape)) assert np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape)
input_value = np.array(np.random.rand(*input_shape)) input_value = np.array(np.random.rand(*input_shape))
if expected_shape is not None: if expected_shape is not None:
expected_value = np.broadcast_to(input_value, int64_array(target_shape)) expected_value = np.broadcast_to(input_value, int64_array(target_shape))
self.assertTrue(np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)), assert np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)),
expected_value)) expected_value)
else: else:
with self.assertRaisesRegex(Exception, '.*cannot be uni-directionally broadcasted.*'): with pytest.raises(Exception,match = '.*cannot be uni-directionally broadcasted.*'):
uni_directional_broadcasting(input_value, int64_array(target_shape)) uni_directional_broadcasting(input_value, int64_array(target_shape))
@generate(*[([], [20, 30, 10], [20, 30, 10]), @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]),
([1], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]),
([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]),
([20, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]),
@ -58,11 +56,11 @@ class TestingBroadcasting(unittest.TestCase):
def test_uni_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): def test_uni_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape):
result = uni_directional_shape_broadcasting(input_shape, target_shape) result = uni_directional_shape_broadcasting(input_shape, target_shape)
if expected_shape is None: if expected_shape is None:
self.assertIsNone(result) assert result is None
else: else:
self.assertTrue(strict_compare_tensors(result, expected_shape)) assert strict_compare_tensors(result, expected_shape)
@generate(*[([], [20, 30, 10], [20, 30, 10]), @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]),
([1], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]),
([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]),
([20, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]),
@ -85,6 +83,6 @@ class TestingBroadcasting(unittest.TestCase):
def test_bi_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): def test_bi_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape):
result = bi_directional_shape_broadcasting(input_shape, target_shape) result = bi_directional_shape_broadcasting(input_shape, target_shape)
if expected_shape is None: if expected_shape is None:
self.assertIsNone(result) assert result is None
else: else:
self.assertTrue(strict_compare_tensors(result, expected_shape)) assert strict_compare_tensors(result, expected_shape)

View File

@ -1,10 +1,9 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import unittest import pytest
import numpy as np import numpy as np
from generator import generator, generate
import openvino.tools.mo.graph.graph import openvino.tools.mo.graph.graph
from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.graph.graph import Node
@ -17,9 +16,8 @@ from unit_tests.utils.graph import connect_data,shaped_parameter, regular_op_wit
from openvino.tools.mo.ops.op import Op from openvino.tools.mo.ops.op import Op
@generator class TestFunction():
class TestFunction(unittest.TestCase): @pytest.mark.parametrize("shape, weights_shape, reshape_shape, group",[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32),
@generate(*[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32),
([1, 32, 112, 112], [32, 1, 1, 1, 3], None, 32), ([1, 32, 112, 112], [32, 1, 1, 1, 3], None, 32),
]) ])
def test_groupconv_to_conv(self, shape, weights_shape, reshape_shape, group): def test_groupconv_to_conv(self, shape, weights_shape, reshape_shape, group):
@ -75,7 +73,7 @@ class TestFunction(unittest.TestCase):
assert len(reshape_node.in_nodes()) == 0 and len(reshape_node.out_nodes()) == 0 assert len(reshape_node.in_nodes()) == 0 and len(reshape_node.out_nodes()) == 0
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_restore_tensor_names(self): def test_restore_tensor_names(self):
@ -144,7 +142,7 @@ class TestFunction(unittest.TestCase):
# Check that graph wasn't changed after shape infer # Check that graph wasn't changed after shape infer
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_squeeze_no_axes(self): def test_squeeze_no_axes(self):
nodes_attributes = { nodes_attributes = {
@ -172,7 +170,7 @@ class TestFunction(unittest.TestCase):
# Check that graph wasn't changed after shape infer # Check that graph wasn't changed after shape infer
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp
def test_unsqueeze(self): def test_unsqueeze(self):
nodes_attributes = { nodes_attributes = {
@ -205,4 +203,4 @@ class TestFunction(unittest.TestCase):
# Check that graph wasn't changed after shape infer # Check that graph wasn't changed after shape infer
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
self.assertTrue(flag, resp) assert flag, resp