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
[PyOV] Extend Python API with STFT-15 (#27142)
Katarzyna Mitrus4043e15cc252
diff --git a/src/bindings/python/src/openvino/runtime/opset15/__init__.py b/src/bindings/python/src/openvino/runtime/opset15/__init__.pyindex 96643a7e93d..58fd90e7fd1 100644--- a/src/bindings/python/src/openvino/runtime/opset15/__init__.py+++ b/src/bindings/python/src/openvino/runtime/opset15/__init__.py@@ -16,3 +16,4 @@ from openvino.runtime.opset15.ops import string_tensor_unpackfrom openvino.runtime.opset15.ops import bitwise_left_shiftfrom openvino.runtime.opset15.ops import bitwise_right_shiftfrom openvino.runtime.opset15.ops import slice_scatter+from openvino.runtime.opset15.ops import stftdiff --git a/src/bindings/python/src/openvino/runtime/opset15/ops.py b/src/bindings/python/src/openvino/runtime/opset15/ops.pyindex 116f63726bf..c278120dab7 100644--- a/src/bindings/python/src/openvino/runtime/opset15/ops.py+++ b/src/bindings/python/src/openvino/runtime/opset15/ops.py@@ -303,3 +303,27 @@ def slice_scatter(inputs = as_nodes(data, updates, start, stop, step, axes, name=name)return _get_node_factory_opset15().create("SliceScatter", inputs)+++@nameable_op+def stft(+ data: NodeInput,+ window: NodeInput,+ frame_size: NodeInput,+ frame_step: NodeInput,+ transpose_frames: bool,+ name: Optional[str] = None,+) -> Node:+ """Return a node which generates STFT 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 transpose_frames: Flag to set output shape layout. If true the `frames` dimension is at out_shape[2],+ otherwise it is at out_shape[1].+ :param name: The optional name for the created output node.+ :return: The new node performing STFT operation.+ """+ inputs = as_nodes(data, window, frame_size, frame_step, name=name)+ return _get_node_factory_opset15().create("STFT", inputs)diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.pyindex c5023588f5d..940f8244f42 100644--- a/src/bindings/python/tests/test_graph/test_create_op.py+++ b/src/bindings/python/tests/test_graph/test_create_op.py@@ -2486,6 +2486,22 @@ def test_slice_scatter():assert node_default_axes.get_output_shape(0) == data_shape+def test_stft():+ data_shape = [4, 48]+ 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))+ transpose_frames = True++ op = ov_opset15.stft(data, window, frame_size, frame_step, transpose_frames)++ assert op.get_type_name() == "STFT"+ assert op.get_output_size() == 1+ assert op.get_output_element_type(0) == Type.f32+ assert op.get_output_shape(0) == [4, 13, 6, 2]++def test_parameter_get_attributes():parameter = ov.parameter([2, 2], dtype=np.float32, name="InputData")parameter_attributes = parameter.get_attributes()