From e3d39e609719bd6daf6ba8c99425f0ab1c33b503 Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:05:25 +0530 Subject: [PATCH 1/6] Create deform_conv.cpp --- .../onnx/frontend/src/deform_conv.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/frontends/onnx/frontend/src/deform_conv.cpp diff --git a/src/frontends/onnx/frontend/src/deform_conv.cpp b/src/frontends/onnx/frontend/src/deform_conv.cpp new file mode 100644 index 00000000000000..ba945852af1ba0 --- /dev/null +++ b/src/frontends/onnx/frontend/src/deform_conv.cpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace ov { +namespace frontend { +namespace onnx { +namespace op { + +class DeformConv : public ov::frontend::onnx::Op { +public: + DeformConv(const std::string& name, int version); + + void operator()(const std::vector& inputs, + const std::vector& attributes, + std::vector& outputs) const override; + +private: + int m_version; // For storing version (19 or 22) to handle datatype differences +}; + +} // namespace op +} // namespace onnx +} // namespace frontend +} // namespace ov From 8c87c2491125f02eba0834765e217b7abbdf2522 Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:07:00 +0530 Subject: [PATCH 2/6] Create deform_conv.hpp --- .../onnx/frontend/src/{deform_conv.cpp => deform_conv.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/frontends/onnx/frontend/src/{deform_conv.cpp => deform_conv.hpp} (100%) diff --git a/src/frontends/onnx/frontend/src/deform_conv.cpp b/src/frontends/onnx/frontend/src/deform_conv.hpp similarity index 100% rename from src/frontends/onnx/frontend/src/deform_conv.cpp rename to src/frontends/onnx/frontend/src/deform_conv.hpp From a6862c9fedfa54d6a488206c8e2124a4dd80c9a2 Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:10:29 +0530 Subject: [PATCH 3/6] Create deform_conv.cpp --- .../onnx/frontend/src/deform_conv.cpp | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/frontends/onnx/frontend/src/deform_conv.cpp diff --git a/src/frontends/onnx/frontend/src/deform_conv.cpp b/src/frontends/onnx/frontend/src/deform_conv.cpp new file mode 100644 index 00000000000000..e828754cdace5f --- /dev/null +++ b/src/frontends/onnx/frontend/src/deform_conv.cpp @@ -0,0 +1,62 @@ +#include "deform_conv.hpp" +#include +#include + +namespace ov { +namespace frontend { +namespace onnx { +namespace op { + +DeformConv::DeformConv(const std::string& name, int version) + : ov::frontend::onnx::Op(name), m_version(version) {} + +void DeformConv::operator()(const std::vector& inputs, + const std::vector& attributes, + std::vector& outputs) const { + // Validate input size, since atleast 3 are needed :) + if (inputs.size() < 3) { + throw std::runtime_error("DeformConv requires at least 3 inputs: data, offsets, weights."); + } + + auto input = inputs[0]; + auto offset = inputs[1]; + auto weight = inputs[2]; + auto bias = inputs.size() > 3 ? inputs[3] : nullptr; // Optional bias + + int64_t groups = 1; + auto groups_attr = ov::frontend::onnx::find_attribute(attributes, "groups"); + if (groups_attr) { + groups = groups_attr->i(); + } + + // Handling datatype differences between DeformConv-19 and DeformConv-22 + ov::element::Type output_type = input.get_element_type(); // Default to input type + + if (m_version == 22) { + auto dtype_attr = ov::frontend::onnx::find_attribute(attributes, "dtype"); + if (dtype_attr) { + output_type = ov::element::Type(dtype_attr->i()); // Set explicit output dtype + } + } + + // Create Deformable Convolution node + auto deform_conv = std::make_shared( + input, offset, weight, bias, + ov::Strides{1, 1}, + ov::CoordinateDiff{0, 0}, + ov::CoordinateDiff{0, 0}, + ov::Strides{1, 1}, + groups + ); + + // Set output type for DeformConv-22 if needed + deform_conv->set_output_type(0, output_type, deform_conv->get_output_partial_shape(0)); + + // Set outputs + outputs.push_back(deform_conv); +} + +} // namespace op +} // namespace onnx +} // namespace frontend +} // namespace ov From bce3c9e0d4d36decd7b016876d87636e8176be6b Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:22:22 +0530 Subject: [PATCH 4/6] Update ops_bridge.cpp Added support for deform_conv --- src/frontends/onnx/frontend/src/ops_bridge.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/frontends/onnx/frontend/src/ops_bridge.cpp b/src/frontends/onnx/frontend/src/ops_bridge.cpp index 64b3b6413eaa40..b69b669b5ab963 100644 --- a/src/frontends/onnx/frontend/src/ops_bridge.cpp +++ b/src/frontends/onnx/frontend/src/ops_bridge.cpp @@ -3,6 +3,7 @@ // #include "ops_bridge.hpp" +#include "deform_conv.hpp" #include #include @@ -216,8 +217,12 @@ OperatorsBridge::OperatorsBridge() { } } // custom ops + // Register the DeformConv-19 and DeformConv-22 operations for ONNX frontend + m_map[""]["DeformConv"].emplace(19, std::bind(op::DeformConv, std::placeholders::_1)); + m_map[""]["DeformConv"].emplace(22, std::bind(op::DeformConv, std::placeholders::_1)); } + #undef REGISTER_OPERATOR #undef REGISTER_OPERATOR_WITH_DOMAIN } // namespace onnx From e05d5875b5c70e44e0192957ec17ea30639b2ce6 Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:27:27 +0530 Subject: [PATCH 5/6] Create deform_conv_model.prototxt --- .../com.microsoft/deform_conv_model.prototxt | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/frontends/onnx/tests/models/com.microsoft/deform_conv_model.prototxt diff --git a/src/frontends/onnx/tests/models/com.microsoft/deform_conv_model.prototxt b/src/frontends/onnx/tests/models/com.microsoft/deform_conv_model.prototxt new file mode 100644 index 00000000000000..bc68031fabfcc6 --- /dev/null +++ b/src/frontends/onnx/tests/models/com.microsoft/deform_conv_model.prototxt @@ -0,0 +1,77 @@ +ir_version: 7 +opset_import { + version: 19 +} +producer_name: "onnx-example" +graph { + node { + input: "data" + input: "offsets" + input: "weights" + output: "output" + op_type: "DeformConv" + domain: "com.microsoft" + attribute { + name: "groups" + type: INT + i: 1 + } + } + name: "DeformConvGraph" + input { + name: "data" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { dim_value: 1 } + dim { dim_value: 3 } + dim { dim_value: 224 } + dim { dim_value: 224 } + } + } + } + } + input { + name: "offsets" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { dim_value: 1 } + dim { dim_value: 18 } + dim { dim_value: 224 } + dim { dim_value: 224 } + } + } + } + } + input { + name: "weights" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { dim_value: 64 } + dim { dim_value: 3 } + dim { dim_value: 3 } + dim { dim_value: 3 } + } + } + } + } + output { + name: "output" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { dim_value: 1 } + dim { dim_value: 64 } + dim { dim_value: 224 } + dim { dim_value: 224 } + } + } + } + } +} From 529cb0548a044625d01f629f9978619fd512d71e Mon Sep 17 00:00:00 2001 From: Harshitha Manne <141660450+darksapien23151@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:42:48 +0530 Subject: [PATCH 6/6] Update onnx_import_com_microsoft.in.cpp Added test cases for deform_conv --- .../tests/onnx_import_com_microsoft.in.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp index 47a336f1749417..44f1621b5d5e1f 100644 --- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp @@ -1653,6 +1653,36 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_add) { test_case.run(); } +OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_deformconv) { + const auto model = convert_model("com.microsoft/deformconv.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + const std::vector data(1 * 3 * 224 * 224, 0); + const std::vector offsets(1 * 18 * 224 * 224, 0.0f); + const std::vector weights(64 * 3 * 3 * 3, 0); + const std::vector data_scale{0.1f}; + const std::vector data_zero_point{0}; + const std::vector weight_scale{0.2f}; + const std::vector weight_zero_point{0}; + const std::vector output_scale{0.3f}; + const std::vector output_zero_point{0}; + + const std::vector expected_output(1 * 64 * 224 * 224, 0); + + test_case.add_input(Shape{1, 3, 224, 224}, data); + test_case.add_input(Shape{1, 18, 224, 224}, offsets); + test_case.add_input(Shape{64, 3, 3, 3}, weights); + test_case.add_input(Shape{1}, data_scale); + test_case.add_input(Shape{1}, data_zero_point); + test_case.add_input(Shape{1}, weight_scale); + test_case.add_input(Shape{1}, weight_zero_point); + test_case.add_input(Shape{1}, output_scale); + test_case.add_input(Shape{1}, output_zero_point); + + test_case.add_expected_output(Shape{1, 64, 224, 224}, expected_output); + test_case.run(); +} + OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_mul) { const auto model = convert_model("com.microsoft/q_linear_mul.onnx"); auto test_case = ov::test::TestCase(model, s_device);