Skip to content

Commit 7160874

Browse files
Support "mask" parameter passed as 4th input of DeformableConv2D node. (openvinotoolkit#24347)
### Details: - This pull request improves [`openvino.convert_model`](https://docs.openvino.ai/2024/api/ie_python_api/_autosummary/openvino.convert_model.html) in Python, so that `DeformableConv2D` can handle the 4th input as `mask` parameter, which is described in [DeformableConvolution-**8**](https://docs.openvino.ai/2023.3/openvino_docs_ops_convolution_DeformableConvolution_8.html). ### Tickets: - Closes openvinotoolkit#24346
1 parent 22dcf50 commit 7160874

File tree

4 files changed

+201
-10
lines changed

4 files changed

+201
-10
lines changed

src/frontends/onnx/frontend/src/op/org.openvinotoolkit/deformable_conv_2d.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "op/org.openvinotoolkit/deformable_conv_2d.hpp"
1818

19+
#include "openvino/frontend/exception.hpp"
1920
#include "openvino/op/deformable_convolution.hpp"
2021
#include "utils/convpool.hpp"
2122

@@ -36,16 +37,32 @@ ov::OutputVector deformable_conv_2d(const ov::frontend::onnx::Node& node) {
3637
const auto deformable_groups = node.get_attribute_value<int64_t>("deformable_groups", 1);
3738
const auto auto_pad_type = convpool::get_auto_pad(node);
3839

39-
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
40-
inputs.at(1),
41-
inputs.at(2),
42-
strides,
43-
paddings.first,
44-
paddings.second,
45-
dilations,
46-
auto_pad_type,
47-
group,
48-
deformable_groups)};
40+
if (inputs.size() == 3) {
41+
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
42+
inputs.at(1),
43+
inputs.at(2),
44+
strides,
45+
paddings.first,
46+
paddings.second,
47+
dilations,
48+
auto_pad_type,
49+
group,
50+
deformable_groups)};
51+
} else if (inputs.size() == 4) {
52+
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
53+
inputs.at(1),
54+
inputs.at(2),
55+
inputs.at(3),
56+
strides,
57+
paddings.first,
58+
paddings.second,
59+
dilations,
60+
auto_pad_type,
61+
group,
62+
deformable_groups)};
63+
} else {
64+
FRONT_END_GENERAL_CHECK(false, "Invalid number of inputs");
65+
}
4966
}
5067
} // namespace set_1
5168
} // namespace op
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
ir_version: 7
2+
producer_name: "OpenVINO ONNX Frontend"
3+
graph {
4+
node {
5+
input: "data"
6+
input: "deformation"
7+
input: "filters"
8+
input: "mask"
9+
output: "out"
10+
op_type: "DeformableConv2D"
11+
}
12+
name: "test_graph"
13+
input {
14+
name: "data"
15+
type {
16+
tensor_type {
17+
elem_type: 1
18+
shape {
19+
dim {
20+
dim_value: 1
21+
}
22+
dim {
23+
dim_value: 1
24+
}
25+
dim {
26+
dim_value: 4
27+
}
28+
dim {
29+
dim_value: 4
30+
}
31+
}
32+
}
33+
}
34+
}
35+
input {
36+
name: "deformation"
37+
type {
38+
tensor_type {
39+
elem_type: 1
40+
shape {
41+
dim {
42+
dim_value: 1
43+
}
44+
dim {
45+
dim_value: 8
46+
}
47+
dim {
48+
dim_value: 3
49+
}
50+
dim {
51+
dim_value: 3
52+
}
53+
}
54+
}
55+
}
56+
}
57+
input {
58+
name: "filters"
59+
type {
60+
tensor_type {
61+
elem_type: 1
62+
shape {
63+
dim {
64+
dim_value: 1
65+
}
66+
dim {
67+
dim_value: 1
68+
}
69+
dim {
70+
dim_value: 2
71+
}
72+
dim {
73+
dim_value: 2
74+
}
75+
}
76+
}
77+
}
78+
}
79+
input {
80+
name: "mask"
81+
type {
82+
tensor_type {
83+
elem_type: 1
84+
shape {
85+
dim {
86+
dim_value: 1
87+
}
88+
dim {
89+
dim_value: 4
90+
}
91+
dim {
92+
dim_value: 3
93+
}
94+
dim {
95+
dim_value: 3
96+
}
97+
}
98+
}
99+
}
100+
}
101+
initializer {
102+
name: "filters"
103+
dims: 1
104+
dims: 1
105+
dims: 2
106+
dims: 2
107+
data_type: 1
108+
float_data: 0.1
109+
float_data: 0.2
110+
float_data: 0.3
111+
float_data: 0.4
112+
}
113+
output {
114+
name: "out"
115+
type {
116+
tensor_type {
117+
elem_type: 1
118+
shape {
119+
dim {
120+
dim_value: 1
121+
}
122+
dim {
123+
dim_value: 1
124+
}
125+
dim {
126+
dim_value: 3
127+
}
128+
dim {
129+
dim_value: 3
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}
136+
opset_import {
137+
version: 7
138+
}

src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,41 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deformable_conv_2d) {
565565
test_case.run();
566566
}
567567

568+
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deformable_conv_2d_with_mask) {
569+
auto model = convert_model("org.openvinotoolkit/deformable_conv_2d_with_mask.onnx");
570+
571+
auto test_case = ov::test::TestCase(model, s_device);
572+
573+
// data
574+
test_case.add_input<float>(
575+
{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f});
576+
577+
// deformations
578+
test_case.add_input<float>({0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f,
579+
1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f,
580+
0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f,
581+
0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f,
582+
1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f,
583+
0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f});
584+
585+
// mask
586+
test_case.add_input<float>({0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f,
587+
1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f,
588+
2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f, 3.1f, 3.2f, 3.3f, 3.4f, 3.5f, 3.6f});
589+
590+
test_case.add_expected_output<float>(Shape{1, 1, 3, 3},
591+
{14.7299995f,
592+
7.3200006f,
593+
15.0600004f,
594+
31.1000004f,
595+
28.9899998f,
596+
20.5800018f,
597+
32.6200027f,
598+
6.6400003f,
599+
1.4399999f});
600+
test_case.run();
601+
}
602+
568603
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_generate_proposals) {
569604
auto model = convert_model("org.openvinotoolkit/generate_proposals.onnx");
570605

src/frontends/onnx/tests/runtime/interpreter/unit_test.manifest

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ onnx_controlflow_loop_power
4545

4646
# No evaluator for DeformableConv2D
4747
onnx_model_deformable_conv_2d
48+
onnx_model_deformable_conv_2d_with_mask
4849

4950
# New fails
5051
onnx_model_quant_conv_linear_3d

0 commit comments

Comments
 (0)