convert_model() in openvino.runtime. (#18080)

* Used pip wheel to build OpenVINO wheel

* Added convert_model() to openvino.runtime.

* Removed duplication of InputCutInfo, LayoutMap

* Switched Model Conversion API tests to convert_model from openvino.runtime.

* Small correction.

* Format correction.

* Small correction.

* Removed duplication of moc frontend files.

* Small correction.

* Removed duplication of cli_parser, offline_transformations.

* Code corrections.

* Removed code duplications.

* Removed code duplications.

* Updated codeowners.

* Switched layer tests to convert_model().

* Improvements

* Small correction.

* Caffe parser path fix.

* Added python api properly into deb / rpm packages

* Moved implementation to ovc tool.

* Moved implementation to ovc tool.

* Small correction.

* Use cmake -E variant from cmake 3.13

* Namespace fixes.

* Minor fixes.

* Pylint fixes.

* Fixed BOM file.

* Small corrections.

* Minor corrections.

* Minor fix.

* Error fixes.

* Added telemetry requirement.

* Improvements to fix CI

* Some refactoring

* Don't use developer package for scripts projects

* Added exception in case when MO is not imported.

* Removed exception from init.

* Removed changes from cmake.

* Added unit ovc tests, fixed minor errors.

* Added ovc unit tests to azure.

* Corrected imports.

* Fixed path to tests.

* Added missed files.

* Corrected github labels.

* Removed benchmark app from dev package.

* Small fix.

* Small corrections.

* Comment fixed.

* Removed changes from setup.py

* Removed not needed change.

* Removed duplicating unit tests.

* Removed wrong change.

* Removed not needed change.

* Apply suggestions from code review

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>

* Added ovc tool test, corrected imports.

* Added legacy TF config test.

* Removed not needed files.

---------

Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
This commit is contained in:
Anastasiia Pnevskaia
2023-06-30 18:26:14 +04:00
committed by GitHub
co-authored by Roman Kazantsev Ilya Lavrenov
parent a2b7d561e4
commit 5d399faa64
133 changed files with 11059 additions and 3017 deletions
@@ -1,7 +1,7 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.tools.mo import convert_model
from openvino.runtime import convert_model
if __name__ == "__main__":
convert_model(help=True)
@@ -4,8 +4,7 @@
import numpy as np
import os
import pytest
from openvino.runtime import Model, Layout, PartialShape, Shape, layout_helpers, Type, Dimension
from openvino.tools.mo.convert import InputCutInfo, LayoutMap
from openvino.runtime import Model, Layout, PartialShape, Shape, layout_helpers, Type, Dimension, InputCutInfo, LayoutMap
from common.mo_convert_test_class import CommonMOConvertTest
from common.tf_layer_test_class import save_to_pb
@@ -9,8 +9,7 @@ import openvino.runtime as ov
import pytest
import torch
import unittest
from openvino.runtime import PartialShape, Dimension, Model, Type
from openvino.tools.mo import InputCutInfo
from openvino.runtime import PartialShape, Dimension, Model, Type, InputCutInfo
from common.mo_convert_test_class import CommonMOConvertTest
@@ -747,7 +746,7 @@ def create_pt_model_with_custom_op():
class ConvertRaises(unittest.TestCase):
def test_example_inputs(self):
from openvino.tools.mo import convert_model
from openvino.runtime import convert_model
pytorch_model = create_pt_model_with_custom_op()
# Check that mo raises error message of wrong argument.
@@ -666,7 +666,7 @@ class TFConvertTest(unittest.TestCase):
@pytest.mark.precommit
def test_tf_function_no_signature(self):
import tensorflow as tf
from openvino.tools.mo import convert_model
from openvino.runtime import convert_model
@tf.function()
def function(x1, x2):
@@ -6,7 +6,7 @@ import os
import sys
import unittest
from openvino.tools.mo import mo
from openvino.tools.mo.utils.cli_parser import get_mo_convert_params
from openvino.tools.ovc.cli_parser import get_mo_convert_params
from pathlib import Path
from common.utils.common_utils import shell
@@ -0,0 +1,89 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import os
import sys
from pathlib import Path
import numpy as np
import openvino.runtime as ov
from openvino.runtime import PartialShape, Model
from openvino.test_utils import compare_functions
from openvino.tools.ovc import ovc
from common.mo_convert_test_class import CommonMOConvertTest
from common.tf_layer_test_class import save_to_pb
from common.utils.common_utils import shell
def generate_ir_ovc(coverage=False, **kwargs):
# Get OVC file directory
ovc_path = Path(ovc.__file__).parent
ovc_runner = ovc_path.joinpath('main.py').as_posix()
if coverage:
params = [sys.executable, '-m', 'coverage', 'run', '-p', '--source={}'.format(ovc_runner.parent),
'--omit=*_test.py', ovc_runner]
else:
params = [sys.executable, ovc_runner]
for key, value in kwargs.items():
if key == "batch":
params.extend(("-b", str(value)))
elif key == "k":
params.extend(("-k", str(value)))
# for FP32 set explicitly compress_to_fp16=False,
# if we omit this argument for FP32, it will be set implicitly to True as the default
elif key == 'compress_to_fp16':
params.append("--{}={}".format(key, value))
elif isinstance(value, bool) and value:
params.append("--{}".format(key))
elif isinstance(value, bool) and not value:
continue
elif (isinstance(value, tuple) and value) or (isinstance(value, str)):
params.extend(("--{}".format(key), str('"{}"'.format(value))))
elif key == "mean_values" and (' ' in value or '(' in value):
params.extend(("--{}".format(key), str('"{}"'.format(value))))
else:
params.extend(("--{}".format(key), str(value)))
exit_code, stdout, stderr = shell(params)
return exit_code, stderr
def create_ref_graph():
shape = PartialShape([1, 3, 2, 2])
param = ov.opset8.parameter(shape, dtype=np.float32)
relu = ov.opset8.relu(param)
sigm = ov.opset8.sigmoid(relu)
return Model([sigm], [param], "test")
class TestOVCTool(CommonMOConvertTest):
def create_tf_model(self, tmp_dir):
import tensorflow as tf
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
inp = tf.compat.v1.placeholder(tf.float32, [1, 3, 2, 2], 'Input')
relu = tf.nn.relu(inp, name='Relu')
output = tf.nn.sigmoid(relu, name='Sigmoid')
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
# save model to .pb and return path to the model
return save_to_pb(tf_net, tmp_dir)
def test_ovc_tool(self, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api):
from openvino.runtime import Core
model_path = self.create_tf_model(temp_dir)
core = Core()
# tests for MO cli tool
exit_code, stderr = generate_ir_ovc(coverage=False, **{"input_model": model_path, "output_dir": temp_dir})
assert not exit_code
ov_model = core.read_model(os.path.join(temp_dir, "model.xml"))
flag, msg = compare_functions(ov_model, create_ref_graph(), False)
assert flag, msg