From d0a8a3914860d0c34dac285fd83cca15efeb031c Mon Sep 17 00:00:00 2001 From: Alicja Miloszewska Date: Thu, 19 Dec 2024 13:53:59 +0100 Subject: [PATCH] [Py OV] Alias classes and functions in flatten openvino namespace (#28085) ### Details: - Add imports from _pyopenivno on the top of the openvino `__init__.py` - Move `Node` binary operators support at the bottom of openvino `__init__.py` Classes and functions available in `openvino/runtime` will match those in flatten `openvino` ### Tickets: - [CVS-129453](https://jira.devtools.intel.com/browse/CVS-129453) --------- Signed-off-by: Alicja Miloszewska Co-authored-by: Michal Lukaszewski --- src/bindings/python/src/openvino/__init__.py | 71 ++++++----- src/bindings/python/src/openvino/_ov_api.py | 4 +- tools/benchmark_tool/openvino/__init__.py | 71 ++++++----- tools/mo/openvino/__init__.py | 123 ++++++++++++------- tools/openvino_dev/src/openvino/__init__.py | 123 ++++++++++++------- tools/ovc/openvino/__init__.py | 71 ++++++----- 6 files changed, 288 insertions(+), 175 deletions(-) diff --git a/src/bindings/python/src/openvino/__init__.py b/src/bindings/python/src/openvino/__init__.py index e3e878564f3313..7643f742e0067d 100644 --- a/src/bindings/python/src/openvino/__init__.py +++ b/src/bindings/python/src/openvino/__init__.py @@ -17,6 +17,47 @@ # # This __init__.py forces checking of runtime modules to propagate errors. # # It is not compared with init files from openvino-dev package. # # + +# Openvino pybind bindings +from openvino._pyopenvino import AxisSet +from openvino._pyopenvino import AxisVector +from openvino._pyopenvino import ConstOutput +from openvino._pyopenvino import Coordinate +from openvino._pyopenvino import CoordinateDiff +from openvino._pyopenvino import DiscreteTypeInfo +from openvino._pyopenvino import Extension +from openvino._pyopenvino import ProfilingInfo +from openvino._pyopenvino import RTMap +from openvino._pyopenvino import Version +from openvino._pyopenvino import Symbol +from openvino._pyopenvino import Dimension +from openvino._pyopenvino import Input +from openvino._pyopenvino import Output +from openvino._pyopenvino import Node +from openvino._pyopenvino import Strides +from openvino._pyopenvino import PartialShape +from openvino._pyopenvino import Shape +from openvino._pyopenvino import Layout +from openvino._pyopenvino import Type +from openvino._pyopenvino import Tensor +from openvino._pyopenvino import OVAny +from openvino._pyopenvino import get_batch +from openvino._pyopenvino import set_batch +from openvino._pyopenvino import serialize +from openvino._pyopenvino import shutdown +from openvino._pyopenvino import save_model +from openvino._pyopenvino import layout_helpers +from openvino._pyopenvino import RemoteContext +from openvino._pyopenvino import RemoteTensor +from openvino._pyopenvino import Op + +# Import public classes from _ov_api +from openvino._ov_api import Model +from openvino._ov_api import Core +from openvino._ov_api import CompiledModel +from openvino._ov_api import InferRequest +from openvino._ov_api import AsyncInferQueue + # Import all public modules from openvino import runtime as runtime from openvino import frontend as frontend @@ -26,36 +67,10 @@ from openvino import utils as utils from openvino import properties as properties -# Import most important classes and functions from openvino.runtime -from openvino._ov_api import Model -from openvino._ov_api import Core -from openvino._ov_api import CompiledModel -from openvino._ov_api import InferRequest -from openvino._ov_api import AsyncInferQueue - -from openvino.runtime import Symbol -from openvino.runtime import Dimension -from openvino.runtime import Strides -from openvino.runtime import PartialShape -from openvino.runtime import Shape -from openvino.runtime import Layout -from openvino.runtime import Type -from openvino.runtime import Tensor -from openvino.runtime import OVAny - # Helper functions for openvino module -from openvino.runtime.utils.data_helpers import tensor_from_file +from openvino.utils.data_helpers import tensor_from_file from openvino._ov_api import compile_model -from openvino.runtime import get_batch -from openvino.runtime import set_batch -from openvino.runtime import serialize -from openvino.runtime import shutdown -from openvino.runtime import save_model -from openvino.runtime import layout_helpers -from openvino._pyopenvino import RemoteContext -from openvino._pyopenvino import RemoteTensor -from openvino._pyopenvino import Op # Import opsets from openvino import opset1 @@ -80,7 +95,7 @@ from openvino._pyopenvino import VASurfaceTensor # Set version for openvino package -from openvino.runtime import get_version +from openvino._pyopenvino import get_version __version__ = get_version() # Tools diff --git a/src/bindings/python/src/openvino/_ov_api.py b/src/bindings/python/src/openvino/_ov_api.py index 1631bc42051418..972ab4a9eb81c0 100644 --- a/src/bindings/python/src/openvino/_ov_api.py +++ b/src/bindings/python/src/openvino/_ov_api.py @@ -4,9 +4,7 @@ from typing import Any, Iterable, Union, Optional, Dict from pathlib import Path -import warnings -import numpy as np from openvino._pyopenvino import Model as ModelBase from openvino._pyopenvino import Core as CoreBase @@ -15,7 +13,7 @@ from openvino._pyopenvino import Tensor from openvino._pyopenvino import Node -from openvino.runtime.utils.data_helpers import ( +from openvino.utils.data_helpers import ( OVDict, _InferRequestWrapper, _data_dispatch, diff --git a/tools/benchmark_tool/openvino/__init__.py b/tools/benchmark_tool/openvino/__init__.py index e3e878564f3313..7643f742e0067d 100644 --- a/tools/benchmark_tool/openvino/__init__.py +++ b/tools/benchmark_tool/openvino/__init__.py @@ -17,6 +17,47 @@ # # This __init__.py forces checking of runtime modules to propagate errors. # # It is not compared with init files from openvino-dev package. # # + +# Openvino pybind bindings +from openvino._pyopenvino import AxisSet +from openvino._pyopenvino import AxisVector +from openvino._pyopenvino import ConstOutput +from openvino._pyopenvino import Coordinate +from openvino._pyopenvino import CoordinateDiff +from openvino._pyopenvino import DiscreteTypeInfo +from openvino._pyopenvino import Extension +from openvino._pyopenvino import ProfilingInfo +from openvino._pyopenvino import RTMap +from openvino._pyopenvino import Version +from openvino._pyopenvino import Symbol +from openvino._pyopenvino import Dimension +from openvino._pyopenvino import Input +from openvino._pyopenvino import Output +from openvino._pyopenvino import Node +from openvino._pyopenvino import Strides +from openvino._pyopenvino import PartialShape +from openvino._pyopenvino import Shape +from openvino._pyopenvino import Layout +from openvino._pyopenvino import Type +from openvino._pyopenvino import Tensor +from openvino._pyopenvino import OVAny +from openvino._pyopenvino import get_batch +from openvino._pyopenvino import set_batch +from openvino._pyopenvino import serialize +from openvino._pyopenvino import shutdown +from openvino._pyopenvino import save_model +from openvino._pyopenvino import layout_helpers +from openvino._pyopenvino import RemoteContext +from openvino._pyopenvino import RemoteTensor +from openvino._pyopenvino import Op + +# Import public classes from _ov_api +from openvino._ov_api import Model +from openvino._ov_api import Core +from openvino._ov_api import CompiledModel +from openvino._ov_api import InferRequest +from openvino._ov_api import AsyncInferQueue + # Import all public modules from openvino import runtime as runtime from openvino import frontend as frontend @@ -26,36 +67,10 @@ from openvino import utils as utils from openvino import properties as properties -# Import most important classes and functions from openvino.runtime -from openvino._ov_api import Model -from openvino._ov_api import Core -from openvino._ov_api import CompiledModel -from openvino._ov_api import InferRequest -from openvino._ov_api import AsyncInferQueue - -from openvino.runtime import Symbol -from openvino.runtime import Dimension -from openvino.runtime import Strides -from openvino.runtime import PartialShape -from openvino.runtime import Shape -from openvino.runtime import Layout -from openvino.runtime import Type -from openvino.runtime import Tensor -from openvino.runtime import OVAny - # Helper functions for openvino module -from openvino.runtime.utils.data_helpers import tensor_from_file +from openvino.utils.data_helpers import tensor_from_file from openvino._ov_api import compile_model -from openvino.runtime import get_batch -from openvino.runtime import set_batch -from openvino.runtime import serialize -from openvino.runtime import shutdown -from openvino.runtime import save_model -from openvino.runtime import layout_helpers -from openvino._pyopenvino import RemoteContext -from openvino._pyopenvino import RemoteTensor -from openvino._pyopenvino import Op # Import opsets from openvino import opset1 @@ -80,7 +95,7 @@ from openvino._pyopenvino import VASurfaceTensor # Set version for openvino package -from openvino.runtime import get_version +from openvino._pyopenvino import get_version __version__ = get_version() # Tools diff --git a/tools/mo/openvino/__init__.py b/tools/mo/openvino/__init__.py index 46e35babdc9fad..7643f742e0067d 100644 --- a/tools/mo/openvino/__init__.py +++ b/tools/mo/openvino/__init__.py @@ -12,56 +12,91 @@ except ImportError: pass -# OpenVINO API -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino import properties as properties +# # +# # OpenVINO API +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue +# Openvino pybind bindings +from openvino._pyopenvino import AxisSet +from openvino._pyopenvino import AxisVector +from openvino._pyopenvino import ConstOutput +from openvino._pyopenvino import Coordinate +from openvino._pyopenvino import CoordinateDiff +from openvino._pyopenvino import DiscreteTypeInfo +from openvino._pyopenvino import Extension +from openvino._pyopenvino import ProfilingInfo +from openvino._pyopenvino import RTMap +from openvino._pyopenvino import Version +from openvino._pyopenvino import Symbol +from openvino._pyopenvino import Dimension +from openvino._pyopenvino import Input +from openvino._pyopenvino import Output +from openvino._pyopenvino import Node +from openvino._pyopenvino import Strides +from openvino._pyopenvino import PartialShape +from openvino._pyopenvino import Shape +from openvino._pyopenvino import Layout +from openvino._pyopenvino import Type +from openvino._pyopenvino import Tensor +from openvino._pyopenvino import OVAny +from openvino._pyopenvino import get_batch +from openvino._pyopenvino import set_batch +from openvino._pyopenvino import serialize +from openvino._pyopenvino import shutdown +from openvino._pyopenvino import save_model +from openvino._pyopenvino import layout_helpers +from openvino._pyopenvino import RemoteContext +from openvino._pyopenvino import RemoteTensor +from openvino._pyopenvino import Op - from openvino.runtime import Symbol - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny +# Import public classes from _ov_api +from openvino._ov_api import Model +from openvino._ov_api import Core +from openvino._ov_api import CompiledModel +from openvino._ov_api import InferRequest +from openvino._ov_api import AsyncInferQueue - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import experimental as experimental +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino import properties as properties - from openvino._pyopenvino import RemoteContext - from openvino._pyopenvino import RemoteTensor - from openvino._pyopenvino import Op +# Helper functions for openvino module +from openvino.utils.data_helpers import tensor_from_file +from openvino._ov_api import compile_model - # libva related: - from openvino._pyopenvino import VAContext - from openvino._pyopenvino import VASurfaceTensor - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# Import opsets +from openvino import opset1 +from openvino import opset2 +from openvino import opset3 +from openvino import opset4 +from openvino import opset5 +from openvino import opset6 +from openvino import opset7 +from openvino import opset8 +from openvino import opset9 +from openvino import opset10 +from openvino import opset11 +from openvino import opset12 +from openvino import opset13 +from openvino import opset14 +from openvino import opset15 +from openvino import opset16 + +# libva related: +from openvino._pyopenvino import VAContext +from openvino._pyopenvino import VASurfaceTensor + +# Set version for openvino package +from openvino._pyopenvino import get_version +__version__ = get_version() # Tools try: diff --git a/tools/openvino_dev/src/openvino/__init__.py b/tools/openvino_dev/src/openvino/__init__.py index 46e35babdc9fad..7643f742e0067d 100644 --- a/tools/openvino_dev/src/openvino/__init__.py +++ b/tools/openvino_dev/src/openvino/__init__.py @@ -12,56 +12,91 @@ except ImportError: pass -# OpenVINO API -try: - # Import all public modules - from openvino import runtime as runtime - from openvino import frontend as frontend - from openvino import helpers as helpers - from openvino import preprocess as preprocess - from openvino import utils as utils - from openvino import properties as properties +# # +# # OpenVINO API +# # This __init__.py forces checking of runtime modules to propagate errors. +# # It is not compared with init files from openvino-dev package. +# # - # Import most important classes and functions from openvino.runtime - from openvino.runtime import Model - from openvino.runtime import Core - from openvino.runtime import CompiledModel - from openvino.runtime import InferRequest - from openvino.runtime import AsyncInferQueue +# Openvino pybind bindings +from openvino._pyopenvino import AxisSet +from openvino._pyopenvino import AxisVector +from openvino._pyopenvino import ConstOutput +from openvino._pyopenvino import Coordinate +from openvino._pyopenvino import CoordinateDiff +from openvino._pyopenvino import DiscreteTypeInfo +from openvino._pyopenvino import Extension +from openvino._pyopenvino import ProfilingInfo +from openvino._pyopenvino import RTMap +from openvino._pyopenvino import Version +from openvino._pyopenvino import Symbol +from openvino._pyopenvino import Dimension +from openvino._pyopenvino import Input +from openvino._pyopenvino import Output +from openvino._pyopenvino import Node +from openvino._pyopenvino import Strides +from openvino._pyopenvino import PartialShape +from openvino._pyopenvino import Shape +from openvino._pyopenvino import Layout +from openvino._pyopenvino import Type +from openvino._pyopenvino import Tensor +from openvino._pyopenvino import OVAny +from openvino._pyopenvino import get_batch +from openvino._pyopenvino import set_batch +from openvino._pyopenvino import serialize +from openvino._pyopenvino import shutdown +from openvino._pyopenvino import save_model +from openvino._pyopenvino import layout_helpers +from openvino._pyopenvino import RemoteContext +from openvino._pyopenvino import RemoteTensor +from openvino._pyopenvino import Op - from openvino.runtime import Symbol - from openvino.runtime import Dimension - from openvino.runtime import Strides - from openvino.runtime import PartialShape - from openvino.runtime import Shape - from openvino.runtime import Layout - from openvino.runtime import Type - from openvino.runtime import Tensor - from openvino.runtime import OVAny +# Import public classes from _ov_api +from openvino._ov_api import Model +from openvino._ov_api import Core +from openvino._ov_api import CompiledModel +from openvino._ov_api import InferRequest +from openvino._ov_api import AsyncInferQueue - from openvino.runtime import compile_model - from openvino.runtime import get_batch - from openvino.runtime import set_batch - from openvino.runtime import serialize - from openvino.runtime import shutdown - from openvino.runtime import tensor_from_file - from openvino.runtime import save_model - from openvino.runtime import layout_helpers +# Import all public modules +from openvino import runtime as runtime +from openvino import frontend as frontend +from openvino import helpers as helpers +from openvino import experimental as experimental +from openvino import preprocess as preprocess +from openvino import utils as utils +from openvino import properties as properties - from openvino._pyopenvino import RemoteContext - from openvino._pyopenvino import RemoteTensor - from openvino._pyopenvino import Op +# Helper functions for openvino module +from openvino.utils.data_helpers import tensor_from_file +from openvino._ov_api import compile_model - # libva related: - from openvino._pyopenvino import VAContext - from openvino._pyopenvino import VASurfaceTensor - # Set version for openvino package - from openvino.runtime import get_version - __version__ = get_version() -except ImportError: - import warnings - warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2) +# Import opsets +from openvino import opset1 +from openvino import opset2 +from openvino import opset3 +from openvino import opset4 +from openvino import opset5 +from openvino import opset6 +from openvino import opset7 +from openvino import opset8 +from openvino import opset9 +from openvino import opset10 +from openvino import opset11 +from openvino import opset12 +from openvino import opset13 +from openvino import opset14 +from openvino import opset15 +from openvino import opset16 + +# libva related: +from openvino._pyopenvino import VAContext +from openvino._pyopenvino import VASurfaceTensor + +# Set version for openvino package +from openvino._pyopenvino import get_version +__version__ = get_version() # Tools try: diff --git a/tools/ovc/openvino/__init__.py b/tools/ovc/openvino/__init__.py index e3e878564f3313..7643f742e0067d 100644 --- a/tools/ovc/openvino/__init__.py +++ b/tools/ovc/openvino/__init__.py @@ -17,6 +17,47 @@ # # This __init__.py forces checking of runtime modules to propagate errors. # # It is not compared with init files from openvino-dev package. # # + +# Openvino pybind bindings +from openvino._pyopenvino import AxisSet +from openvino._pyopenvino import AxisVector +from openvino._pyopenvino import ConstOutput +from openvino._pyopenvino import Coordinate +from openvino._pyopenvino import CoordinateDiff +from openvino._pyopenvino import DiscreteTypeInfo +from openvino._pyopenvino import Extension +from openvino._pyopenvino import ProfilingInfo +from openvino._pyopenvino import RTMap +from openvino._pyopenvino import Version +from openvino._pyopenvino import Symbol +from openvino._pyopenvino import Dimension +from openvino._pyopenvino import Input +from openvino._pyopenvino import Output +from openvino._pyopenvino import Node +from openvino._pyopenvino import Strides +from openvino._pyopenvino import PartialShape +from openvino._pyopenvino import Shape +from openvino._pyopenvino import Layout +from openvino._pyopenvino import Type +from openvino._pyopenvino import Tensor +from openvino._pyopenvino import OVAny +from openvino._pyopenvino import get_batch +from openvino._pyopenvino import set_batch +from openvino._pyopenvino import serialize +from openvino._pyopenvino import shutdown +from openvino._pyopenvino import save_model +from openvino._pyopenvino import layout_helpers +from openvino._pyopenvino import RemoteContext +from openvino._pyopenvino import RemoteTensor +from openvino._pyopenvino import Op + +# Import public classes from _ov_api +from openvino._ov_api import Model +from openvino._ov_api import Core +from openvino._ov_api import CompiledModel +from openvino._ov_api import InferRequest +from openvino._ov_api import AsyncInferQueue + # Import all public modules from openvino import runtime as runtime from openvino import frontend as frontend @@ -26,36 +67,10 @@ from openvino import utils as utils from openvino import properties as properties -# Import most important classes and functions from openvino.runtime -from openvino._ov_api import Model -from openvino._ov_api import Core -from openvino._ov_api import CompiledModel -from openvino._ov_api import InferRequest -from openvino._ov_api import AsyncInferQueue - -from openvino.runtime import Symbol -from openvino.runtime import Dimension -from openvino.runtime import Strides -from openvino.runtime import PartialShape -from openvino.runtime import Shape -from openvino.runtime import Layout -from openvino.runtime import Type -from openvino.runtime import Tensor -from openvino.runtime import OVAny - # Helper functions for openvino module -from openvino.runtime.utils.data_helpers import tensor_from_file +from openvino.utils.data_helpers import tensor_from_file from openvino._ov_api import compile_model -from openvino.runtime import get_batch -from openvino.runtime import set_batch -from openvino.runtime import serialize -from openvino.runtime import shutdown -from openvino.runtime import save_model -from openvino.runtime import layout_helpers -from openvino._pyopenvino import RemoteContext -from openvino._pyopenvino import RemoteTensor -from openvino._pyopenvino import Op # Import opsets from openvino import opset1 @@ -80,7 +95,7 @@ from openvino._pyopenvino import VASurfaceTensor # Set version for openvino package -from openvino.runtime import get_version +from openvino._pyopenvino import get_version __version__ = get_version() # Tools