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 ROIAlignRotated-15 (#25755)
Hubert Błaszczykcb09e4fb6909
diff --git a/src/bindings/python/src/openvino/runtime/opset15/__init__.py b/src/bindings/python/src/openvino/runtime/opset15/__init__.pyindex d7040d974c1..13087ef74a7 100644--- a/src/bindings/python/src/openvino/runtime/opset15/__init__.py+++ b/src/bindings/python/src/openvino/runtime/opset15/__init__.py@@ -10,3 +10,4 @@ from openvino.runtime.opset15.ops import col2imfrom openvino.runtime.opset15.ops import embedding_bag_offsetsfrom openvino.runtime.opset15.ops import embedding_bag_packedfrom openvino.runtime.opset15.ops import scatter_nd_update+from openvino.runtime.opset15.ops import roi_align_rotateddiff --git a/src/bindings/python/src/openvino/runtime/opset15/ops.py b/src/bindings/python/src/openvino/runtime/opset15/ops.pyindex 5613de6bd82..8ed73361db1 100644--- a/src/bindings/python/src/openvino/runtime/opset15/ops.py+++ b/src/bindings/python/src/openvino/runtime/opset15/ops.py@@ -144,3 +144,45 @@ def embedding_bag_packed(inputs.append(per_sample_weights)return _get_node_factory_opset15().create("EmbeddingBagPacked", as_nodes(*inputs, name=name), {"reduction": reduction})+++@nameable_op+def roi_align_rotated(+ data: NodeInput,+ rois: NodeInput,+ batch_indices: NodeInput,+ pooled_h: int,+ pooled_w: int,+ sampling_ratio: int,+ spatial_scale: float,+ clockwise_mode: bool,+ name: Optional[str] = None,+) -> Node:+ """Return a node which performs ROIAlignRotated operation.++ :param data: Input data.+ :param rois: RoIs (Regions of Interest) to pool over.+ :param batch_indices: Tensor with each element denoting the index of+ the corresponding image in the batch.+ :param pooled_h: Height of the ROI output feature map.+ :param pooled_w: Width of the ROI output feature map.+ :param sampling_ratio: Number of bins over height and width to use to calculate+ each output feature map element.+ :param spatial_scale: Multiplicative spatial scale factor to translate ROI coordinates.+ :param clockwise_mode: If true, rotation angle is interpreted as clockwise,+ otherwise as counterclockwise+ :param name: The optional name for the output node++ :return: The new node which performs ROIAlignRotated+ """+ return _get_node_factory_opset15().create(+ "ROIAlignRotated",+ as_nodes(data, rois, batch_indices, name=name),+ {+ "pooled_h": pooled_h,+ "pooled_w": pooled_w,+ "sampling_ratio": sampling_ratio,+ "spatial_scale": spatial_scale,+ "clockwise_mode": clockwise_mode,+ },+ )diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.pyindex 006a0b12d32..6a6d3cea2ba 100644--- a/src/bindings/python/tests/test_graph/test_create_op.py+++ b/src/bindings/python/tests/test_graph/test_create_op.py@@ -12,6 +12,7 @@ from openvino.runtime.utils.types import make_constant_nodeimport openvino.runtime.opset1 as ov_opset1import openvino.runtime.opset5 as ov_opset5import openvino.runtime.opset10 as ov_opset10+import openvino.runtime.opset15 as ov_opset15import openvino.runtime.opset11 as ovfrom openvino.runtime.op.util import VariableInfo, Variable@@ -885,6 +886,37 @@ def test_roi_align(data_shape, rois, batch_indices, pooled_h, pooled_w, samplingassert list(node.get_output_shape(0)) == expected_shape+ ("data_shape", "rois", "batch_indices", "pooled_h", "pooled_w", "sampling_ratio", "spatial_scale", "clockwise_mode", "expected_shape"),+ [+ ([2, 3, 5, 6], [7, 5], [7], 2, 2, 1, 1.0, True, [7, 3, 2, 2]),+ ([10, 3, 5, 5], [7, 5], [7], 3, 4, 1, 1.0, True, [7, 3, 3, 4]),+ ([10, 3, 5, 5], [3, 5], [3], 3, 4, 1, 1.0, False, [3, 3, 3, 4]),+ ([10, 3, 5, 5], [3, 5], [3], 3, 4, 1, float(1), False, [3, 3, 3, 4]),+ ],+)+def test_roi_align_rotated(data_shape, rois, batch_indices, pooled_h, pooled_w, sampling_ratio, spatial_scale, clockwise_mode, expected_shape):+ data_parameter = ov.parameter(data_shape, name="Data", dtype=np.float32)+ rois_parameter = ov.parameter(rois, name="Rois", dtype=np.float32)+ batch_indices_parameter = ov.parameter(batch_indices, name="Batch_indices", dtype=np.int32)++ node = ov_opset15.roi_align_rotated(+ data_parameter,+ rois_parameter,+ batch_indices_parameter,+ pooled_h,+ pooled_w,+ sampling_ratio,+ spatial_scale,+ clockwise_mode,+ )++ assert node.get_type_name() == "ROIAlignRotated"+ assert node.get_output_size() == 1+ assert node.get_output_element_type(0) == Type.f32+ assert list(node.get_output_shape(0)) == expected_shape++@pytest.mark.parametrize("op_name", ["psroipooling", "psroiPoolingOpset1"])def test_psroi_pooling(op_name):inputs = ov.parameter([1, 72, 4, 5], dtype=np.float32)