Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Py OV] Add utils to openvino module #28062

Merged
merged 10 commits into from
Dec 16, 2024
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 @@ -7,7 +7,7 @@
# Required for Windows OS platforms
# Note: always top-level
try:
from openvino.utils import _add_openvino_libs_to_search_path
from openvino.package_utils import _add_openvino_libs_to_search_path
_add_openvino_libs_to_search_path()
except ImportError:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def _add_openvino_libs_to_search_path() -> None:
if os.path.isdir(os.path.join(os.path.dirname(__file__), "libs")):
# looking for the libs in the pip installation path.
openvino_libs.append(os.path.join(os.path.dirname(__file__), "libs"))
elif os.path.isdir(os.path.join(os.path.dirname(__file__), "..", "..", "..", "Library", "bin")):
elif os.path.isdir(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, "Library", "bin")):
# looking for the libs in the conda installation path
openvino_libs.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "Library", "bin"))
openvino_libs.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, "Library", "bin"))
else:
# setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable.
openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS")
Expand Down
22 changes: 0 additions & 22 deletions src/bindings/python/src/openvino/runtime/opset_utils.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from openvino.utils.node_factory import _get_node_factory
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

"""Generic utilities. Factor related functions out to separate files."""

from openvino._pyopenvino.util import numpy_to_c, replace_node, replace_output_update_name
from openvino.utils import numpy_to_c, replace_node, replace_output_update_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should raise a warning about its deprecation since 2025 and our intention to remove in 2026 release.
It relates all runtime modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a task to raise a warning about runtime deprecation. You can track the progress here in jira

from openvino.utils.broadcasting import get_broadcast_axes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.runtime.utils.data_helpers.data_dispatcher import _data_dispatch
from openvino.runtime.utils.data_helpers.wrappers import tensor_from_file
from openvino.runtime.utils.data_helpers.wrappers import _InferRequestWrapper
from openvino.runtime.utils.data_helpers.wrappers import OVDict
from openvino.utils.data_helpers.data_dispatcher import _data_dispatch
from openvino.utils.data_helpers.wrappers import tensor_from_file
from openvino.utils.data_helpers.wrappers import _InferRequestWrapper
from openvino.utils.data_helpers.wrappers import OVDict
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from openvino.utils.data_helpers.data_dispatcher import ContainerTypes
from openvino.utils.data_helpers.data_dispatcher import ScalarTypes
from openvino.utils.data_helpers.data_dispatcher import ValidKeys

from openvino.utils.data_helpers.data_dispatcher import is_list_simple_type
from openvino.utils.data_helpers.data_dispatcher import get_request_tensor
from openvino.utils.data_helpers.data_dispatcher import value_to_tensor
from openvino.utils.data_helpers.data_dispatcher import to_c_style
from openvino.utils.data_helpers.data_dispatcher import normalize_arrays
from openvino.utils.data_helpers.data_dispatcher import create_shared
from openvino.utils.data_helpers.data_dispatcher import set_request_tensor
from openvino.utils.data_helpers.data_dispatcher import update_tensor
from openvino.utils.data_helpers.data_dispatcher import update_inputs
from openvino.utils.data_helpers.data_dispatcher import create_copied
from openvino.utils.data_helpers.data_dispatcher import _data_dispatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from openvino.utils.data_helpers.wrappers import tensor_from_file
from openvino.utils.data_helpers.wrappers import _InferRequestWrapper
from openvino.utils.data_helpers.wrappers import OVDict
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.decorators import _get_name
from openvino.utils.decorators import _set_node_friendly_name
from openvino.utils.decorators import nameable_op
from openvino.utils.decorators import unary_op
from openvino.utils.decorators import binary_op
from openvino.utils.decorators import custom_preprocess_function
from openvino.utils.decorators import MultiMethod
from openvino.utils.decorators import registry
from openvino.utils.decorators import overloading
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.input_validation import assert_list_of_ints
from openvino.utils.input_validation import _check_value
from openvino.utils.input_validation import check_valid_attribute
from openvino.utils.input_validation import check_valid_attributes
from openvino.utils.input_validation import is_positive_value
from openvino.utils.input_validation import is_non_negative_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.node_factory import NodeFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.reduction import get_reduction_axes
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.types import TensorShape
from openvino.utils.types import NumericData
from openvino.utils.types import NumericType
from openvino.utils.types import ScalarData
from openvino.utils.types import NodeInput

from openvino.utils.types import openvino_to_numpy_types_map
from openvino.utils.types import openvino_to_numpy_types_str_map
from openvino.utils.types import get_element_type
from openvino.utils.types import get_element_type_str
from openvino.utils.types import get_dtype
from openvino.utils.types import get_numpy_ctype
from openvino.utils.types import get_ndarray
from openvino.utils.types import get_shape
from openvino.utils.types import make_constant_node
from openvino.utils.types import as_node
from openvino.utils.types import as_nodes
12 changes: 12 additions & 0 deletions src/bindings/python/src/openvino/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""Generic utilities. Factor related functions out to separate files."""

from openvino._pyopenvino.util import numpy_to_c, replace_node, replace_output_update_name

from openvino.package_utils import get_cmake_path
from openvino.package_utils import deprecated
from openvino.package_utils import classproperty
from openvino.package_utils import deprecatedclassproperty
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from typing import List, Optional
from typing import Optional

from openvino.runtime import AxisSet, Node
from openvino.runtime.utils.types import (
NodeInput,
from openvino.runtime import AxisSet
from openvino.utils.types import (
TensorShape,
get_dtype,
make_constant_node,
)

log = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.utils.data_helpers.data_dispatcher import _data_dispatch
from openvino.utils.data_helpers.wrappers import tensor_from_file
from openvino.utils.data_helpers.wrappers import _InferRequestWrapper
from openvino.utils.data_helpers.wrappers import OVDict
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np

from openvino._pyopenvino import ConstOutput, Tensor, Type, RemoteTensor
from openvino.runtime.utils.data_helpers.wrappers import _InferRequestWrapper, OVDict
from openvino.utils.data_helpers.wrappers import _InferRequestWrapper, OVDict

ContainerTypes = Union[dict, list, tuple, OVDict]
ScalarTypes = Union[np.number, int, float]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, Callable, Dict, Optional, Union, get_origin, get_args

from openvino.runtime import Node, Output
from openvino.runtime.utils.types import NodeInput, as_node, as_nodes
from openvino.utils.types import NodeInput, as_node, as_nodes


def _get_name(**kwargs: Any) -> Node:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging as log
almilosz marked this conversation as resolved.
Show resolved Hide resolved

from functools import partial, singledispatchmethod
from functools import singledispatchmethod
from typing import Any, Dict, List, Optional, Union
from pathlib import Path

Expand Down Expand Up @@ -125,3 +125,11 @@ def _arguments_as_outputs(arguments: List[Union[Node, Output]]) -> List[Output]:
else:
outputs.extend(argument.outputs())
return outputs


def _get_node_factory(opset_version: Optional[str] = None) -> NodeFactory:
"""Return NodeFactory configured to create operators from specified opset version."""
if opset_version:
return NodeFactory(opset_version)
else:
return NodeFactory()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from openvino.runtime.exceptions import OVTypeError
from openvino.runtime import Node, Shape, Output, Type
from openvino.runtime.op import Constant
from openvino.op import Constant

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tools/benchmark_tool/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Required for Windows OS platforms
# Note: always top-level
try:
from openvino.utils import _add_openvino_libs_to_search_path
from openvino.package_utils import _add_openvino_libs_to_search_path
_add_openvino_libs_to_search_path()
except ImportError:
pass
Expand Down
2 changes: 1 addition & 1 deletion tools/mo/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Required for Windows OS platforms
# Note: always top-level
try:
from openvino.utils import _add_openvino_libs_to_search_path
from openvino.package_utils import _add_openvino_libs_to_search_path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not touch it please because we are removing it this release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there are still some samples that depend on it.
I had to touch it because wheels_windows_vs2019_release CI failed.

almilosz marked this conversation as resolved.
Show resolved Hide resolved
_add_openvino_libs_to_search_path()
except ImportError:
pass
Expand Down
2 changes: 1 addition & 1 deletion tools/openvino_dev/src/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Required for Windows OS platforms
# Note: always top-level
try:
from openvino.utils import _add_openvino_libs_to_search_path
from openvino.package_utils import _add_openvino_libs_to_search_path
almilosz marked this conversation as resolved.
Show resolved Hide resolved
almilosz marked this conversation as resolved.
Show resolved Hide resolved
_add_openvino_libs_to_search_path()
except ImportError:
pass
Expand Down
2 changes: 1 addition & 1 deletion tools/ovc/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Required for Windows OS platforms
# Note: always top-level
try:
from openvino.utils import _add_openvino_libs_to_search_path
from openvino.package_utils import _add_openvino_libs_to_search_path
_add_openvino_libs_to_search_path()
except ImportError:
pass
Expand Down
Loading