Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV][Op] Extend Python API with ISTFT-16 (#29293)

Katarzyna Mitrus883ea3a01475
diff --git a/src/bindings/python/src/openvino/opset16/__init__.py b/src/bindings/python/src/openvino/opset16/__init__.py
index b4757cb245d..231f2914013 100644
--- a/src/bindings/python/src/openvino/opset16/__init__.py
+++ b/src/bindings/python/src/openvino/opset16/__init__.py
@@ -4,6 +4,7 @@
# New operations added in Opset16
from openvino.opset16.ops import identity
+from openvino.opset16.ops import istft
from openvino.opset16.ops import segment_max
# Operators from previous opsets
diff --git a/src/bindings/python/src/openvino/opset16/ops.py b/src/bindings/python/src/openvino/opset16/ops.py
index 5d82e578388..de7e57deb1a 100644
--- a/src/bindings/python/src/openvino/opset16/ops.py
+++ b/src/bindings/python/src/openvino/opset16/ops.py
@@ -34,6 +34,40 @@ def identity(
)
+@nameable_op
+def istft(
+ data: NodeInput,
+ window: NodeInput,
+ frame_size: NodeInput,
+ frame_step: NodeInput,
+ center: bool,
+ normalized: bool,
+ signal_length: Optional[NodeInput] = None,
+ name: Optional[str] = None,
+) -> Node:
+ """Return a node which generates ISTFT operation.
+
+ :param data: The node providing input data.
+ :param window: The node providing window data.
+ :param frame_size: The node with scalar value representing the size of Fourier Transform.
+ :param frame_step: The distance (number of samples) between successive window frames.
+ :param center: Flag signaling if the signal input has been padded before STFT.
+ :param normalized: Flag signaling if the STFT result has been normalized.
+ :param signal_length: The optional node with length of the original signal.
+ :param name: The optional name for the created output node.
+ :return: The new node performing ISTFT operation.
+ """
+ if signal_length is None:
+ inputs = as_nodes(data, window, frame_size, frame_step, name=name)
+ else:
+ inputs = as_nodes(data, window, frame_size, frame_step, signal_length, name=name)
+ return _get_node_factory_opset16().create(
+ "ISTFT",
+ inputs,
+ {"center": center, "normalized": normalized},
+ )
+
+
@nameable_op
def segment_max(
data: NodeInput,
diff --git a/src/bindings/python/src/openvino/runtime/opset16/__init__.py b/src/bindings/python/src/openvino/runtime/opset16/__init__.py
index 87cbd3f644b..028452c4817 100644
--- a/src/bindings/python/src/openvino/runtime/opset16/__init__.py
+++ b/src/bindings/python/src/openvino/runtime/opset16/__init__.py
@@ -6,6 +6,7 @@ from openvino.runtime.opset16 import ops
# New operations added in Opset16
from openvino.opset16.ops import identity
+from openvino.opset16.ops import istft
from openvino.opset16.ops import segment_max
# Operators from previous opsets
diff --git a/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py b/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py
index 85f094651b2..566efc11530 100644
--- a/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py
+++ b/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py
@@ -3,4 +3,5 @@
# SPDX-License-Identifier: Apache-2.0
from openvino.opset16.ops import identity
+from openvino.opset16.ops import istft
from openvino.opset16.ops import segment_max
diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.py
index 6e2d02ea658..5a3a12adfe1 100644
--- a/src/bindings/python/tests/test_graph/test_create_op.py
+++ b/src/bindings/python/tests/test_graph/test_create_op.py
@@ -13,6 +13,7 @@ import openvino.opset1 as ov_opset1
import openvino.opset5 as ov_opset5
import openvino.opset10 as ov_opset10
import openvino.opset15 as ov_opset15
+import openvino.opset16 as ov_opset16
import openvino.opset11 as ov
from openvino.op.util import VariableInfo, Variable
@@ -2252,6 +2253,42 @@ def test_stft():
assert op.get_output_shape(0) == [4, 6, 13, 2]
+def test_istft():
+ data_shape = [4, 6, 13, 2]
+ data = ov.parameter(data_shape, name="input", dtype=np.float32)
+ window = ov.parameter([7], name="window", dtype=np.float32)
+ frame_size = ov.constant(np.array(11, dtype=np.int32))
+ frame_step = ov.constant(np.array(3, dtype=np.int32))
+
+ center = False
+ normalized = True
+ op = ov_opset16.istft(data, window, frame_size, frame_step, center, normalized)
+
+ assert op.get_type_name() == "ISTFT"
+ assert op.get_output_size() == 1
+ assert op.get_output_element_type(0) == Type.f32
+ assert op.get_output_shape(0) == [4, 47]
+
+ center = True
+ normalized = False
+ op = ov_opset16.istft(data, window, frame_size, frame_step, center, normalized)
+
+ assert op.get_type_name() == "ISTFT"
+ assert op.get_output_size() == 1
+ assert op.get_output_element_type(0) == Type.f32
+ assert op.get_output_shape(0) == [4, 37]
+
+ signal_length = ov.constant(np.array(48, dtype=np.int32))
+ center = False
+ normalized = False
+ op = ov_opset16.istft(data, window, frame_size, frame_step, center, normalized, signal_length)
+
+ assert op.get_type_name() == "ISTFT"
+ assert op.get_output_size() == 1
+ assert op.get_output_element_type(0) == Type.f32
+ assert op.get_output_shape(0) == [4, 48]
+
+
def test_search_sorted():
sorted_sequence = ov.parameter([7, 256, 200, 200], name="sorted", dtype=np.float32)
values = ov.parameter([7, 256, 200, 10], name="values", dtype=np.float32)