OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[PyAPI] Add Identity-16 Operation (#26717)
Piotr Krzemiński3c5744e171e0
diff --git a/src/bindings/python/src/openvino/runtime/opset16/__init__.py b/src/bindings/python/src/openvino/runtime/opset16/__init__.pyindex bf155b81312..ce52690e919 100644--- a/src/bindings/python/src/openvino/runtime/opset16/__init__.py+++ b/src/bindings/python/src/openvino/runtime/opset16/__init__.py@@ -3,6 +3,7 @@# SPDX-License-Identifier: Apache-2.0# New operations added in Opset16+from openvino.runtime.opset16.ops import identity# Operators from previous opsets# TODO (ticket: 156877): Add previous opset operators at the end of opset16 developmentdiff --git a/src/bindings/python/src/openvino/runtime/opset16/ops.py b/src/bindings/python/src/openvino/runtime/opset16/ops.pyindex 0825ccb9d0f..60656f6d993 100644--- a/src/bindings/python/src/openvino/runtime/opset16/ops.py+++ b/src/bindings/python/src/openvino/runtime/opset16/ops.py@@ -4,9 +4,31 @@"""Factory functions for ops added to openvino opset16."""from functools import partial+from typing import Optional+from openvino.runtime import Node+from openvino.runtime.utils.decorators import nameable_opfrom openvino.runtime.opset_utils import _get_node_factory+from openvino.runtime.utils.types import NodeInput, as_nodes_get_node_factory_opset16 = partial(_get_node_factory, "opset16")# -------------------------------------------- ops ------------------------------------------------+++@nameable_op+def identity(+ data: NodeInput,+ name: Optional[str] = None,+) -> Node:+ """Identity operation is used as a placeholder. It creates a copy of the input to forward to the output.++ :param data: Tensor with data.++ :return: The new node performing Identity operation.+ """+ return _get_node_factory_opset16().create(+ "Identity",+ as_nodes(data, name=name),+ {},+ )diff --git a/src/bindings/python/tests/test_graph/test_identity.py b/src/bindings/python/tests/test_graph/test_identity.pynew file mode 100644index 00000000000..fea1c88858c--- /dev/null+++ b/src/bindings/python/tests/test_graph/test_identity.py@@ -0,0 +1,31 @@+# -*- coding: utf-8 -*-+# Copyright (C) 2018-2024 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import numpy as np+import pytest++from openvino.runtime.opset15 import parameter+from openvino.runtime.opset16 import identity+from openvino import PartialShape, Type+++ ("input_shape", "expected_output_shape"),+ [+ ([4, 4], PartialShape([4, 4])),+ ([10, 8, 8], PartialShape([10, 8, 8])),+ ([-1, -1, -1], PartialShape([-1, -1, -1])),+ ([10, -1, -1], PartialShape([10, -1, -1])),+ ],+)[email protected]("op_name", ["identity", "identityOpset16"])+def test_inverse_param_inputs(input_shape, expected_output_shape, op_name):+ data = parameter(input_shape, dtype=np.float32)++ op = identity(data, name=op_name)+ assert op.get_output_size() == 1+ assert op.get_type_name() == "Identity"+ assert op.get_friendly_name() == op_name+ assert op.get_output_element_type(0) == Type.f32+ assert op.get_output_partial_shape(0) == expected_output_shape