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
[ONNX FE] Unsupported operation DeformConv (#38909)
Szymon Gutajc15cc1029b15
diff --git a/src/frontends/onnx/docs/supported_ops.md b/src/frontends/onnx/docs/supported_ops.mdindex 7ea834064d9..688980e657b 100644--- a/src/frontends/onnx/docs/supported_ops.md+++ b/src/frontends/onnx/docs/supported_ops.md@@ -51,7 +51,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)| |Crop |1 | | || |CumSum |11 |14, 11 | || |DFT |17 |20, 17 | |-| |DeformConv | |22, 19 | |+| |DeformConv |19 |22, 19 |Only 2D convolution (rank-4 inputs)|| |DepthToSpace |1 |13, 11, 1 | || |DequantizeLinear |21, 19, 13, 10 |21, 19, 13, 10 | || |Det | |22, 11 | |diff --git a/src/frontends/onnx/frontend/sources.cmake b/src/frontends/onnx/frontend/sources.cmakeindex 788be2a7c56..1c5b50f8033 100644--- a/src/frontends/onnx/frontend/sources.cmake+++ b/src/frontends/onnx/frontend/sources.cmake@@ -77,6 +77,7 @@ set(op_list${CMAKE_CURRENT_LIST_DIR}/src/op/cosh.cpp${CMAKE_CURRENT_LIST_DIR}/src/op/crop.cpp${CMAKE_CURRENT_LIST_DIR}/src/op/cum_sum.cpp+ ${CMAKE_CURRENT_LIST_DIR}/src/op/deform_conv.cpp${CMAKE_CURRENT_LIST_DIR}/src/op/depth_to_space.cpp${CMAKE_CURRENT_LIST_DIR}/src/op/dequantize_linear.cpp${CMAKE_CURRENT_LIST_DIR}/src/op/dft.cppdiff --git a/src/frontends/onnx/frontend/src/op/deform_conv.cpp b/src/frontends/onnx/frontend/src/op/deform_conv.cppnew file mode 100644index 00000000000..2c120c29a12--- /dev/null+++ b/src/frontends/onnx/frontend/src/op/deform_conv.cpp@@ -0,0 +1,94 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "core/null_node.hpp"+#include "core/operator_set.hpp"+#include "openvino/frontend/exception.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/deformable_convolution.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/shape_of.hpp"+#include "utils/convpool.hpp"+#include "utils/reshape.hpp"+using namespace ov::op;++namespace ov::frontend::onnx::ai_onnx::opset_1 {+ov::OutputVector deform_conv(const ov::frontend::onnx::Node& node) {+ const ov::OutputVector& inputs = node.get_ov_inputs();+ FRONT_END_GENERAL_CHECK(inputs.size() >= 3 && inputs.size() <= 5,+ "DeformConv expects between 3 and 5 inputs, got: ",+ inputs.size());++ // ONNX DeformConv inputs: X, W, offset, [B], [mask]+ const auto& data = inputs.at(0);+ const auto& filters = inputs.at(1);+ const auto& offsets = inputs.at(2);+ const auto bias = inputs.size() >= 4 ? inputs.at(3) : ov::Output<ov::Node>{std::make_shared<NullNode>()};+ const auto mask = inputs.size() == 5 ? inputs.at(4) : ov::Output<ov::Node>{std::make_shared<NullNode>()};++ const auto strides = convpool::get_strides(node);+ const auto dilations = convpool::get_dilations(node);+ const auto paddings = convpool::get_pads(node);+ const auto auto_pad_type = convpool::get_auto_pad(node);++ const auto group = node.get_attribute_value<int64_t>("group", 1);+ const auto offset_group = node.get_attribute_value<int64_t>("offset_group", 1);++ FRONT_END_GENERAL_CHECK(offset_group > 0, "DeformConv offset_group must be greater than zero");+ const auto& data_shape = data.get_partial_shape();+ if (data_shape.rank().is_static() && data_shape.rank().get_length() > 1 && data_shape[1].is_static()) {+ FRONT_END_GENERAL_CHECK(data_shape[1].get_length() % offset_group == 0,+ "DeformConv input channels (",+ data_shape[1].get_length(),+ ") must be evenly divisible by offset_group (",+ offset_group,+ ")");+ }++ // ONNX samples zero when the location lies outside of the padded input tensor,+ // which corresponds to bilinear interpolation on the zero-padded feature map.+ constexpr bool bilinear_interpolation_pad = true;++ std::shared_ptr<ov::Node> deformable_conv;+ if (ov::op::util::is_null(mask)) {+ deformable_conv = std::make_shared<v8::DeformableConvolution>(data,+ offsets,+ filters,+ strides,+ paddings.first,+ paddings.second,+ dilations,+ auto_pad_type,+ group,+ offset_group,+ bilinear_interpolation_pad);+ } else {+ deformable_conv = std::make_shared<v8::DeformableConvolution>(data,+ offsets,+ filters,+ mask,+ strides,+ paddings.first,+ paddings.second,+ dilations,+ auto_pad_type,+ group,+ offset_group,+ bilinear_interpolation_pad);+ }++ if (ov::op::util::is_null(bias)) {+ return {deformable_conv};+ }++ const auto conv_rank = std::make_shared<v3::ShapeOf>(std::make_shared<v3::ShapeOf>(deformable_conv));+ const auto reshaped_bias = reshape::reshape_channel_shaped_node_to_nchw(bias, conv_rank);+ return {std::make_shared<v1::Add>(deformable_conv, reshaped_bias)};+}++// DeformConv is defined since opset 19, but it is registered since opset 1,+// because OperatorsBridge requires a translator for every version imported by a model.+ONNX_OP("DeformConv", OPSET_SINCE(1), ai_onnx::opset_1::deform_conv);+} // namespace ov::frontend::onnx::ai_onnx::opset_1diff --git a/src/frontends/onnx/tests/__init__.py b/src/frontends/onnx/tests/__init__.pyindex a6bf48d53b6..03fb34f995c 100644--- a/src/frontends/onnx/tests/__init__.py+++ b/src/frontends/onnx/tests/__init__.py@@ -137,7 +137,6 @@ xfail_issue_119900 = xfail_test(reason="While validating ONNX node '<Node(Resize"is not supported. Choose one of the following modes: ""tf_half_pixel_for_nn, asymmetric, align_corners, pytorch_half_pixel, ""half_pixel")-xfail_issue_119903 = xfail_test(reason="DeformConv operation is not supported")xfail_issue_119919 = xfail_test(reason="While validating ONNX node '<Node(Pad): y>': Unsupported padding mode: [wrap]")xfail_issue_119922 = xfail_test(reason="ai.onnx.ml operators domain isn't supported")xfail_issue_119925 = xfail_test(reason="AveragePool AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07")diff --git a/src/frontends/onnx/tests/models/deform_conv_2d.prototxt b/src/frontends/onnx/tests/models/deform_conv_2d.prototxtnew file mode 100644index 00000000000..ad9cbcf52c8--- /dev/null+++ b/src/frontends/onnx/tests/models/deform_conv_2d.prototxt@@ -0,0 +1,83 @@+ir_version: 9+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "X"+ input: "W"+ input: "offset"+ output: "Y"+ op_type: "DeformConv"+ attribute {+ name: "kernel_shape"+ ints: 2+ ints: 2+ type: INTS+ }+ attribute {+ name: "pads"+ ints: 0+ ints: 0+ ints: 0+ ints: 0+ type: INTS+ }+ }+ name: "test_deform_conv"+ initializer {+ name: "W"+ dims: 1+ dims: 1+ dims: 2+ dims: 2+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "offset"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+opset_import {+ version: 19+}diff --git a/src/frontends/onnx/tests/models/deform_conv_2d_invalid_offset_group_channels.prototxt b/src/frontends/onnx/tests/models/deform_conv_2d_invalid_offset_group_channels.prototxtnew file mode 100644index 00000000000..af83d5af38b--- /dev/null+++ b/src/frontends/onnx/tests/models/deform_conv_2d_invalid_offset_group_channels.prototxt@@ -0,0 +1,76 @@+ir_version: 9+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "X"+ input: "W"+ input: "offset"+ output: "Y"+ op_type: "DeformConv"+ attribute {+ name: "offset_group"+ i: 2+ type: INT+ }+ }+ name: "test_deform_conv_invalid_offset_group_channels"+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "W"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 3 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ input {+ name: "offset"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 16 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+opset_import {+ version: 19+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/deform_conv_2d_with_mask_bias.prototxt b/src/frontends/onnx/tests/models/deform_conv_2d_with_mask_bias.prototxtnew file mode 100644index 00000000000..92ef6138ee9--- /dev/null+++ b/src/frontends/onnx/tests/models/deform_conv_2d_with_mask_bias.prototxt@@ -0,0 +1,115 @@+ir_version: 9+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "X"+ input: "W"+ input: "offset"+ input: "B"+ input: "mask"+ output: "Y"+ op_type: "DeformConv"+ attribute {+ name: "kernel_shape"+ ints: 2+ ints: 2+ type: INTS+ }+ attribute {+ name: "pads"+ ints: 0+ ints: 0+ ints: 0+ ints: 0+ type: INTS+ }+ }+ name: "test_deform_conv_with_mask_bias"+ initializer {+ name: "W"+ dims: 1+ dims: 1+ dims: 2+ dims: 2+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ }+ initializer {+ name: "B"+ dims: 1+ data_type: 1+ float_data: 1.0+ }+ initializer {+ name: "mask"+ dims: 1+ dims: 4+ dims: 2+ dims: 2+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 0.2+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "offset"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+opset_import {+ version: 19+}diff --git a/src/frontends/onnx/tests/models/deform_conv_2d_with_offset_groups.prototxt b/src/frontends/onnx/tests/models/deform_conv_2d_with_offset_groups.prototxtnew file mode 100644index 00000000000..4dd596d71b4--- /dev/null+++ b/src/frontends/onnx/tests/models/deform_conv_2d_with_offset_groups.prototxt@@ -0,0 +1,92 @@+ir_version: 9+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "X"+ input: "W"+ input: "offset"+ output: "Y"+ op_type: "DeformConv"+ attribute {+ name: "kernel_shape"+ ints: 2+ ints: 2+ type: INTS+ }+ attribute {+ name: "pads"+ ints: 0+ ints: 0+ ints: 0+ ints: 0+ type: INTS+ }+ attribute {+ name: "offset_group"+ i: 2+ type: INT+ }+ }+ name: "test_deform_conv_with_offset_groups"+ initializer {+ name: "W"+ dims: 1+ dims: 2+ dims: 2+ dims: 2+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "offset"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 16 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+opset_import {+ version: 19+}diff --git a/src/frontends/onnx/tests/models/deform_conv_2d_with_padding.prototxt b/src/frontends/onnx/tests/models/deform_conv_2d_with_padding.prototxtnew file mode 100644index 00000000000..c870ceae6dd--- /dev/null+++ b/src/frontends/onnx/tests/models/deform_conv_2d_with_padding.prototxt@@ -0,0 +1,83 @@+ir_version: 9+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "X"+ input: "W"+ input: "offset"+ output: "Y"+ op_type: "DeformConv"+ attribute {+ name: "kernel_shape"+ ints: 2+ ints: 2+ type: INTS+ }+ attribute {+ name: "pads"+ ints: 1+ ints: 1+ ints: 1+ ints: 1+ type: INTS+ }+ }+ name: "test_deform_conv_with_padding"+ initializer {+ name: "W"+ dims: 1+ dims: 1+ dims: 2+ dims: 2+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "offset"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 8 }+ dim { dim_value: 4 }+ dim { dim_value: 4 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 1 }+ dim { dim_value: 4 }+ dim { dim_value: 4 }+ }+ }+ }+ }+}+opset_import {+ version: 19+}diff --git a/src/frontends/onnx/tests/onnx_import_convpool.in.cpp b/src/frontends/onnx/tests/onnx_import_convpool.in.cppindex ac6915954c4..7cd7db891e8 100644--- a/src/frontends/onnx/tests/onnx_import_convpool.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_convpool.in.cpp@@ -20,6 +20,7 @@#include "common_test_utils/test_case.hpp"#include "common_test_utils/test_control.hpp"#include "common_test_utils/test_tools.hpp"+#include "gmock/gmock.h"#include "gtest/gtest.h"#include "onnx_utils.hpp"#include "openvino/op/max_pool.hpp"@@ -292,6 +293,92 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_conv_transpose_w_groups) {test_case.run();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deform_conv_2d) {+ auto model = convert_model("deform_conv_2d.onnx");++ auto test_case = ov::test::TestCase(model, s_device);++ // X (1, 1, 3, 3)+ test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});++ // offset (1, 8, 2, 2): h-coord of kernel[0,0] at out[0,0] = 0.5, w-coord of kernel[1,0] at out[0,1] = -0.1+ std::vector<float> offset(32, 0.f);+ offset[0] = 0.5f;+ offset[21] = -0.1f;+ test_case.add_input<float>(offset);++ test_case.add_expected_output<float>(Shape{1, 1, 2, 2}, {9.5f, 11.9f, 20.f, 24.f});+ test_case.run();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deform_conv_2d_with_padding) {+ auto model = convert_model("deform_conv_2d_with_padding.onnx");++ auto test_case = ov::test::TestCase(model, s_device);++ // X (1, 1, 3, 3)+ test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});++ // offset (1, 8, 4, 4): h-coord of kernel[0,0] at out[0,0] = 0.5, w-coord of kernel[1,0] at out[1,2] = -0.1+ std::vector<float> offset(128, 0.f);+ offset[0] = 0.5f;+ offset[86] = -0.1f;+ test_case.add_input<float>(offset);++ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 4},+ {0.f, 1.f, 3.f, 2.f, 3.f, 8.f, 11.9f, 7.f, 9.f, 20.f, 24.f, 13.f, 6.f, 13.f, 15.f, 8.f});+ test_case.run();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deform_conv_2d_with_mask_bias) {+ auto model = convert_model("deform_conv_2d_with_mask_bias.onnx");++ auto test_case = ov::test::TestCase(model, s_device);++ // X (1, 1, 3, 3)+ test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});++ // offset (1, 8, 2, 2): same as the basic case+ std::vector<float> offset(32, 0.f);+ offset[0] = 0.5f;+ offset[21] = -0.1f;+ test_case.add_input<float>(offset);++ test_case.add_expected_output<float>(Shape{1, 1, 2, 2}, {10.5f, 12.9f, 21.f, 19.4f});+ test_case.run();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deform_conv_2d_with_offset_groups) {+ auto model = convert_model("deform_conv_2d_with_offset_groups.onnx");++ auto test_case = ov::test::TestCase(model, s_device);++ // X (1, 2, 3, 3): channel 0 is arange(9), channel 1 is arange(8, -1, -1)+ test_case.add_input<float>(+ {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 8.f, 7.f, 6.f, 5.f, 4.f, 3.f, 2.f, 1.f, 0.f});++ // offset (1, 16, 2, 2): h-coord of kernel[0,0] (group 0) at out[0,0] = 0.5,+ // w-coord of kernel[1,0] (group 1) at out[0,1] = -0.1+ std::vector<float> offset(64, 0.f);+ offset[0] = 0.5f;+ offset[53] = -0.1f;+ test_case.add_input<float>(offset);++ test_case.add_expected_output<float>(Shape{1, 1, 2, 2}, {33.5f, 32.1f, 32.f, 32.f});+ test_case.run();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deform_conv_2d_invalid_offset_group_channels) {+ try {+ convert_model("deform_conv_2d_invalid_offset_group_channels.onnx");+ FAIL() << "Expected DeformConv input channel validation to fail";+ } catch (const ov::Exception& error) {+ EXPECT_THAT(error.what(),+ testing::HasSubstr("DeformConv input channels (3) must be evenly divisible by offset_group (2)"));+ }+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_average_pool_2d) {// Pooling with strides=2 and no paddingauto model = convert_model("average_pool_2d.onnx");diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.pyindex e1a42957f9e..1b2050a6f95 100644--- a/src/frontends/onnx/tests/tests_python/test_backend.py+++ b/src/frontends/onnx/tests/tests_python/test_backend.py@@ -43,7 +43,6 @@ from tests import (xfail_issue_119896,skip_issue_119896,xfail_issue_119900,- xfail_issue_119903,xfail_issue_119919,xfail_issue_119922,xfail_issue_119925,@@ -401,13 +400,6 @@ tests_expected_to_fail = ["OnnxBackendNodeModelTest.test_resize_downsample_scales_linear_half_pixel_symmetric_cpu","OnnxBackendNodeModelTest.test_resize_upsample_scales_linear_half_pixel_symmetric_cpu",),- (- xfail_issue_119903,- "OnnxBackendNodeModelTest.test_basic_deform_conv_with_padding_cpu",- "OnnxBackendNodeModelTest.test_basic_deform_conv_without_padding_cpu",- "OnnxBackendNodeModelTest.test_deform_conv_with_mask_bias_cpu",- "OnnxBackendNodeModelTest.test_deform_conv_with_multiple_offset_groups_cpu",- ),(xfail_issue_119919,"OnnxBackendNodeModelTest.test_wrap_pad_cpu",