Skip to content

Commit

Permalink
Removed InputCutInfo, disabled input cut in OVC. (openvinotoolkit#18927)
Browse files Browse the repository at this point in the history
* Fixed output_model logic.

* Removed InputCutInfo, disabled input cut in ovc.

* Disabled output cut, added tests for setting shapes or types for not all inputs.

* Returned support of numpy type.

* Separated MO and OVC python API tests.

* Small corrections.

* Added output dir test, exceptions test.

* Tests fixed.

* Corrected extension param description.

* Corrected input description, minor code corrections.
  • Loading branch information
popovaan authored Aug 10, 2023
1 parent 5f71679 commit 59872ee
Show file tree
Hide file tree
Showing 39 changed files with 2,883 additions and 836 deletions.
9 changes: 9 additions & 0 deletions .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,15 @@ jobs:
TEST_DEVICE: CPU
displayName: 'TensorFlow Lite Layer Tests - TFL FE'
- script: |
set -e
python3 -m pip install -r $(LAYER_TESTS_DIR)/requirements.txt
$(RUN_PREFIX) python3 -m pytest $(LAYER_TESTS_DIR)/ovc_python_api_tests/ --junitxml=./TEST-test_ovc_convert.xmlTEST
env:
PYTHONPATH: $(LAYER_TESTS_DIR)
TEST_DEVICE: CPU
displayName: 'OVC Python API Tests'
- script: |
set -e
python3 -m pip install -r $(LAYER_TESTS_DIR)/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/src/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
# Tools
try:
# Model Conversion API - ovc should reside in the main namespace
from openvino.tools.ovc import convert_model, InputCutInfo
from openvino.tools.ovc import convert_model
except ImportError:
pass
2 changes: 1 addition & 1 deletion tests/layer_tests/common/mo_convert_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _test(self, temp_dir, test_params, ref_params):
ir_ref = core.read_model(Path(temp_dir, 'model_ref.xml'))

flag, msg = compare_functions(ir_test, ir_ref)
assert flag, '\n'.join(msg)
assert flag, msg

def _test_by_ref_graph(self, temp_dir, test_params, ref_graph, compare_tensor_names=True, compare_layout=True):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import os
import pytest
from openvino.runtime import Model, Layout, PartialShape, Shape, layout_helpers, Type, Dimension
from openvino.tools.ovc import InputCutInfo
from openvino.tools.mo import LayoutMap

from openvino.tools.mo import LayoutMap, InputCutInfo
import openvino.runtime as ov
from common.mo_convert_test_class import CommonMOConvertTest
from common.tf_layer_test_class import save_to_pb

Expand Down Expand Up @@ -134,11 +133,11 @@ def create_tf_param_res_model(self, tmp_dir):
{'params_test': {'input_shape': [PartialShape([2, 3, 4]),
[2, 3, 4],
[Dimension(2), Dimension(3), Dimension(4)]],
'input':['Input1', 'Input2', 'Relu3'], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
'input':['Input1', 'Input2', 'Relu3'], 'compress_to_fp16': True},
'params_ref': {'input_shape': "[2,3,4],[2,3,4],[2,3,4]", 'input': 'Input1,Input2,Relu3'}},
{'params_test': {'input_shape': [PartialShape([Dimension(), Dimension(1, 3), Dimension(4, -1), Dimension(-1, 5)]),
[Dimension(), Dimension(1, 3), 4, Dimension(-1, 5)],
[Dimension(), 3, Dimension(4, -1), Dimension(-1, 5)]], 'use_convert_model_from_mo': True,
[Dimension(), 3, Dimension(4, -1), Dimension(-1, 5)]],
'compress_to_fp16': True,
'input':['Input1', 'Input2', 'Relu3']},
'params_ref': {'input_shape': "[?,1..3,4..,..5],[?,1..3,4,..5],[?,3,4..,..5]", 'input': 'Input1,Input2,Relu3'}},
Expand All @@ -153,32 +152,27 @@ def create_tf_param_res_model(self, tmp_dir):
{'params_test': {'output': ["Sigmoid_0", "Sigmoid_2"]},
'params_ref': {'output': "Sigmoid_0,Sigmoid_2"}},
{'params_test': {'mean_values': {'Input1': [0.5,1.3,0.67], 'Input2':[4.2, 6.7, 3.15], 'Input3':[0.757, 4.6, 7.3]},
'use_convert_model_from_mo': True, 'compress_to_fp16': True},
'compress_to_fp16': True},
'params_ref': {'mean_values': "Input1[0.5,1.3,0.67],Input2[4.2,6.7,3.15],Input3[0.757,4.6,7.3]"}},
{'params_test': {
'mean_values': [[0.5, 1.3, 0.67], [4.2, 6.7, 3.15], [0.757, 4.6, 7.3]], 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
'mean_values': [[0.5, 1.3, 0.67], [4.2, 6.7, 3.15], [0.757, 4.6, 7.3]], 'compress_to_fp16': True},
'params_ref': {'mean_values': "[0.5,1.3,0.67],[4.2,6.7,3.15],[0.757,4.6,7.3]"}},
{'params_test': {'scale_values': {'Input1': [0.5,1.3,0.67], 'Input2':[4.2, 6.7, 3.15], 'Input3':[0.757, 4.6, 7.3]},
'use_convert_model_from_mo': True, 'compress_to_fp16': True},
'compress_to_fp16': True},
'params_ref': {'scale_values': "Input1[0.5,1.3,0.67],Input2[4.2,6.7,3.15],Input3[0.757,4.6,7.3]"}},
{'params_test': {
'scale_values': [[0.5, 1.3, 0.67], [4.2, 6.7, 3.15], [0.757, 4.6, 7.3]], 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
'scale_values': [[0.5, 1.3, 0.67], [4.2, 6.7, 3.15], [0.757, 4.6, 7.3]], 'compress_to_fp16': True},
'params_ref': {'scale_values': "[0.5,1.3,0.67],[4.2,6.7,3.15],[0.757,4.6,7.3]"}},
{'params_test': {
'source_layout': {'Input1': Layout("nchw"), 'Input2': "nchw", 'Input3': "nc??"}, 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
'source_layout': {'Input1': Layout("nchw"), 'Input2': "nchw", 'Input3': "nc??"}, 'compress_to_fp16': True},
'params_ref': {'source_layout': "Input1(nchw),Input2(nchw),Input3(nc??)"}},
{'params_test': {
'target_layout': {'Input1': Layout("nhwc"), 'Input2': "nhwc", 'Input3': "n??c"}, 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
'target_layout': {'Input1': Layout("nhwc"), 'Input2': "nhwc", 'Input3': "n??c"}, 'compress_to_fp16': True},
'params_ref': {'target_layout': "Input1(nhwc),Input2(nhwc),Input3(n??c)"}},
{'params_test': {
'layout': {'Input1': LayoutMap(source_layout=Layout("nchw"), target_layout="nhwc"),
'Input2': LayoutMap(source_layout="nc??", target_layout=Layout("n??c")),
'Input3': LayoutMap(source_layout="abcd", target_layout="acdb")}, 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
'Input3': LayoutMap(source_layout="abcd", target_layout="acdb")}, 'compress_to_fp16': True},
'params_ref': {'layout': "Input1(nchw->nhwc),Input2(nc??->n??c),Input3(abcd->acdb)"}},
{'params_test': {'input': [PartialShape([2, 3, 4]), [2, 3, 4], [Dimension(2), Dimension(3), Dimension(4)]]},
'params_ref': {'input_shape': "[2,3,4],[2,3,4],[2,3,4]", 'input': 'Input1,Input2,Input3'}},
Expand All @@ -198,6 +192,7 @@ def test_mo_convert_tf_model(self, params, ie_device, precision, ir_version,

test_params = params['params_test']
ref_params = params['params_ref']
test_params.update({'use_convert_model_from_mo': True})
test_params.update({'input_model': tf_net_path})
ref_params.update({'input_model': tf_net_path})
self._test(temp_dir, test_params, ref_params)
Expand Down Expand Up @@ -241,16 +236,13 @@ def test_mo_convert_tf_model_no_concat(self, params, ie_device, precision, ir_ve
# By default compress_to_fp16 in Python API is False but for mo cli tool (used for params_ref) it's True.
# compress_to_fp16 should be specified explicitly either in 'param_test' or 'params_ref' (or in both)
# Check all args combinations.
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'compress_to_fp16': True},
'params_ref': {'input_shape': "[2,3,4]"}},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'use_convert_model_from_mo': True},
{'params_test': {'input_shape': PartialShape([2, 3, 4])},
'params_ref': {'input_shape': "[2,3,4]", 'compress_to_fp16': False}},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'compress_to_fp16': True},
'params_ref': {'input_shape': "[2,3,4]", 'compress_to_fp16': True}},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'use_convert_model_from_mo': True,
'compress_to_fp16': False},
{'params_test': {'input_shape': PartialShape([2, 3, 4]), 'compress_to_fp16': False},
'params_ref': {'input_shape': "[2,3,4]", 'compress_to_fp16': False}},

# ovc.convert_model with save_model are used, by default save_model compresses to fp16 same as cli tool.
Expand All @@ -266,8 +258,7 @@ def test_mo_convert_tf_model_no_concat(self, params, ie_device, precision, ir_ve
{'params_test': {'input': InputCutInfo("Relu", [3, 2], Type(np.int32), [1, 2, 3, 4, 5, 6]), 'compress_to_fp16': False},
'params_ref': {'input': "Relu[3 2]{i32}->[1 2 3 4 5 6]", 'compress_to_fp16': False}},

{'params_test': {'input_shape': [Dimension(), Dimension(1, 3), 4, Dimension(-1, 5)], 'use_convert_model_from_mo': True,
'compress_to_fp16': True},
{'params_test': {'input_shape': [Dimension(), Dimension(1, 3), 4, Dimension(-1, 5)], 'compress_to_fp16': True},
'params_ref': {'input_shape': "[?,1..3,4,..5]"}},
{'params_test': {'input': InputCutInfo("Relu", [3, 2], Type(np.int32), [1, 2, 3, 4, 5, 6])},
'params_ref': {'input': "Relu[3 2]{i32}->[1 2 3 4 5 6]"}},
Expand All @@ -279,18 +270,17 @@ def test_mo_convert_tf_model_no_concat(self, params, ie_device, precision, ir_ve
'params_ref': {'input': "Relu[3 2]"}},
{'params_test': {'input': ("Relu")},
'params_ref': {'input': "Relu"}},
{'params_test': {'mean_values': [0.5, 1.3, 0.67], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'mean_values': [0.5, 1.3, 0.67], 'compress_to_fp16': True},
'params_ref': {'mean_values': "[0.5,1.3,0.67]"}},
{'params_test': {'scale_values': [0.5, 1.3, 0.67], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'scale_values': [0.5, 1.3, 0.67], 'compress_to_fp16': True},
'params_ref': {'scale_values': "[0.5,1.3,0.67]"}},
{'params_test': {'source_layout': Layout("nchw"), 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'source_layout': Layout("nchw"), 'compress_to_fp16': True},
'params_ref': {'source_layout': "nchw"}},
{'params_test': {'target_layout': Layout("nchw"), 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'target_layout': Layout("nchw"), 'compress_to_fp16': True},
'params_ref': {'target_layout': "nchw"}},
{'params_test': {'layout': LayoutMap(source_layout=Layout("nchw"), target_layout="nhwc"),
'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'layout': LayoutMap(source_layout=Layout("nchw"), target_layout="nhwc"), 'compress_to_fp16': True},
'params_ref': {'layout': "nchw->nhwc"}},
{'params_test': {'layout': Layout("nchw"), 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'layout': Layout("nchw"), 'compress_to_fp16': True},
'params_ref': {'layout': "nchw"}},
{'params_test': {'input': [3, 2]},
'params_ref': {'input': "Input[3 2]"}},
Expand All @@ -306,13 +296,13 @@ def test_mo_convert_tf_model_no_concat(self, params, ie_device, precision, ir_ve
'params_ref': {'input': "Input[1]{i32}->[10]"}},
{'params_test': {'input': (np.int32, [1, 2, 3])},
'params_ref': {'input': "Input[1,2,3]{i32}"}},
{'params_test': {'input_shape': [Dimension(3, 10), 10, -1], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'input_shape': [Dimension(3, 10), 10, -1], 'compress_to_fp16': True},
'params_ref': {'input_shape': '[3..10,10,?]'}},
{'params_test': {'input': [Dimension(3, 10), 10, -1]},
'params_ref': {'input': 'Input[3..10,10,?]'}},
{'params_test': {'input': PartialShape([1, 100, 100, 3]), 'mean_values': [0.5, 1.3, 0.67], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'input': PartialShape([1, 100, 100, 3]), 'mean_values': [0.5, 1.3, 0.67], 'compress_to_fp16': True},
'params_ref': {'input': "Input[1,100,100,3]", 'mean_values': "[0.5,1.3,0.67]"}},
{'params_test': {'input': [1, 100, 100, 3], 'scale_values': [0.5, 1.3, 0.67], 'use_convert_model_from_mo': True, 'compress_to_fp16': True},
{'params_test': {'input': [1, 100, 100, 3], 'scale_values': [0.5, 1.3, 0.67], 'compress_to_fp16': True},
'params_ref': {'input': "Input[1,100,100,3]", 'scale_values': "[0.5,1.3,0.67]"}},
]

Expand All @@ -325,6 +315,7 @@ def test_mo_convert_tf_model_single_input_output(self, params, ie_device, precis

test_params = params['params_test']
ref_params = params['params_ref']
test_params.update({'use_convert_model_from_mo': True})
test_params.update({'input_model': tf_net_path})
ref_params.update({'input_model': tf_net_path})
self._test(temp_dir, test_params, ref_params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def create_ref_graph2():
return Model([sigmoid], [param], "test")

test_data = [
{'params_test': {'extension': create_custom_extension_leaky_relu_to_relu()},
{'params_test': {'extensions': create_custom_extension_leaky_relu_to_relu()},
'ref_graph': create_ref_graph1()},
{'params_test': {'extension': [create_custom_extension_leaky_relu_to_relu(),
{'params_test': {'extensions': [create_custom_extension_leaky_relu_to_relu(),
create_custom_extension_elu_to_sigmoid()]},
'ref_graph': create_ref_graph2()}
]
Expand All @@ -118,4 +118,5 @@ def test_mo_convert_extensions(self, params, ie_device, precision, ir_version,

test_params = params['params_test']
test_params.update({'input_model': onnx_net_path})
test_params.update({'use_convert_model_from_mo': True})
self._test_by_ref_graph(temp_dir, test_params, params['ref_graph'])
6 changes: 3 additions & 3 deletions tests/layer_tests/mo_python_api_tests/test_mo_convert_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def make_graph_proto_model():

def create_ref_model(shape):
param1 = ov.opset8.parameter(shape, dtype=np.float32)
slope_const = ov.opset8.constant([0.1], dtype=np.float16)
decompress_slope = ov.opset8.convert(slope_const, np.float32)
prelu = ov.opset8.prelu(param1, slope=decompress_slope)
slope_const = ov.opset8.constant([0.1], dtype=np.float32)
prelu = ov.opset8.prelu(param1, slope=slope_const)
relu = ov.opset8.elu(prelu, alpha=np.float32(0.1))
parameter_list = [param1]
return Model([relu], parameter_list, "test")
Expand Down Expand Up @@ -79,5 +78,6 @@ def test_mo_convert_onnx(self, create_model, ie_device, precision, ir_version,
test_params = {'input_model': fw_model}
if mo_params is not None:
test_params.update(mo_params)
test_params.update({'use_convert_model_from_mo': True})
self._test_by_ref_graph(temp_dir, test_params, graph_ref, compare_tensor_names=False)

Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ def test_mo_import_from_memory_paddle_fe(self, create_model, ie_device, precisio
test_params = {'input_model': fw_model, 'use_new_frontend': True}
if mo_params is not None:
test_params.update(mo_params)
test_params.update({'use_convert_model_from_mo': True})
self._test_by_ref_graph(temp_dir, test_params, graph_ref, compare_tensor_names=False)
Loading

0 comments on commit 59872ee

Please sign in to comment.