Skip to content

Commit 0dfd2f0

Browse files
committed
Feat: Extend ONNX FE with Com2Im operator (#30144)
1 parent 9fe6071 commit 0dfd2f0

11 files changed

+817
-9
lines changed

src/frontends/onnx/docs/supported_ops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)
3535
| |Celu |12 |12 | |
3636
| |CenterCropPad |18 |18 | |
3737
| |Clip |11, 1 |13, 12, 11, 6, 1 | |
38-
| |Col2Im | |18 | |
38+
| |Col2Im |18 |18 | |
3939
| |Compress |9 |11, 9 | |
4040
| |Concat |1 |13, 11, 4, 1 | |
4141
| |ConcatFromSequence |11 |11 |Supported only in certain patterns|
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (C) 2018-2026 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "openvino/op/col2im.hpp"
6+
7+
#include "core/operator_set.hpp"
8+
#include "exceptions.hpp"
9+
#include "utils/common.hpp"
10+
11+
namespace ov {
12+
namespace frontend {
13+
namespace onnx {
14+
namespace ai_onnx {
15+
namespace opset_18 {
16+
ov::OutputVector col2im(const ov::frontend::onnx::Node& node) {
17+
// 1. get inputs
18+
common::default_op_checks(node, 3);
19+
const auto inputs = node.get_ov_inputs();
20+
const auto& data = inputs[0]; // input
21+
const auto& output_size = inputs[1]; // image_shape
22+
const auto& kernel_size = inputs[2]; // block_shape
23+
24+
// 2. get attributes
25+
const size_t spatial_rank = 2;
26+
27+
std::vector<size_t> default_attr_vals(spatial_rank, 1);
28+
auto dilations = node.get_attribute_value<std::vector<size_t>>("dilations", default_attr_vals);
29+
auto strides = node.get_attribute_value<std::vector<size_t>>("strides", default_attr_vals);
30+
31+
std::vector<size_t> default_pads(spatial_rank * 2, 0);
32+
auto pads = node.get_attribute_value<std::vector<size_t>>("pads", default_pads);
33+
std::vector<size_t> pads_begin;
34+
std::vector<size_t> pads_end;
35+
36+
// ov::op::v15::Col2Im only supports 2D spatial dimensions
37+
CHECK_VALID_NODE(node,
38+
dilations.size() == spatial_rank,
39+
"Col2Im 'dilations' attribute must have size [2]. Got: ",
40+
dilations.size());
41+
CHECK_VALID_NODE(node,
42+
strides.size() == spatial_rank,
43+
"Col2Im 'strides' attribute must have size [2]. Got: ",
44+
strides.size());
45+
CHECK_VALID_NODE(node,
46+
pads.size() == spatial_rank * 2,
47+
"Col2Im 'pads' attribute must have size [4]. Got: ",
48+
pads.size());
49+
50+
// spatial_rank == pads.size() / 2
51+
pads_begin.assign(pads.begin(), pads.begin() + spatial_rank);
52+
pads_end.assign(pads.begin() + spatial_rank, pads.end());
53+
54+
// 3. return Col2Im
55+
return {
56+
std::make_shared<ov::op::v15::Col2Im>(data, output_size, kernel_size, strides, dilations, pads_begin, pads_end)
57+
->outputs()};
58+
}
59+
60+
ONNX_OP("Col2Im", OPSET_SINCE(1), ai_onnx::opset_18::col2im);
61+
} // namespace opset_18
62+
} // namespace ai_onnx
63+
} // namespace onnx
64+
} // namespace frontend
65+
} // namespace ov

src/frontends/onnx/tests/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright (C) 2018-2026 Intel Corporation
32
# SPDX-License-Identifier: Apache-2.0
3+
# -*- coding: utf-8 -*-
44

55
import pytest
66

@@ -52,7 +52,6 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):
5252
"Axes input must be constant")
5353
skip_bitwise_ui64 = pytest.mark.skip(reason="AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07")
5454
xfail_issue_99950 = xfail_test(reason="CenterCropPad func is not supported")
55-
xfail_issue_99952 = xfail_test(reason="Col2Im operator is not supported")
5655
xfail_issue_99954 = xfail_test(reason="Constant Pad - RuntimeError: Shape inference of Reference node with name y failed")
5756
xfail_issue_99955 = xfail_test(reason="GroupNorm is not supported")
5857
xfail_issue_99957 = xfail_test(reason="LayerNorm - RuntimeError: While validating node '<Node(Reshape): Mean>'")
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
ir_version: 8
2+
producer_name: "OpenVINO ONNX Frontend"
3+
graph {
4+
node {
5+
input: "input"
6+
input: "image_shape"
7+
input: "block_shape"
8+
output: "output"
9+
name: "col2im_2D_batch_opset_18"
10+
op_type: "Col2Im"
11+
attribute {
12+
name: "dilations"
13+
ints: 1
14+
ints: 1
15+
type: INTS
16+
}
17+
attribute {
18+
name: "pads"
19+
ints: 0
20+
ints: 0
21+
ints: 0
22+
ints: 0
23+
type: INTS
24+
}
25+
attribute {
26+
name: "strides"
27+
ints: 1
28+
ints: 1
29+
type: INTS
30+
}
31+
}
32+
name: "col2im_2D_batch_opset_18"
33+
input {
34+
name: "input"
35+
type {
36+
tensor_type {
37+
elem_type: 1
38+
shape {
39+
dim {
40+
dim_value: 2
41+
}
42+
dim {
43+
dim_value: 4
44+
}
45+
dim {
46+
dim_value: 4
47+
}
48+
}
49+
}
50+
}
51+
}
52+
input {
53+
name: "image_shape"
54+
type {
55+
tensor_type {
56+
elem_type: 7
57+
shape {
58+
dim {
59+
dim_value: 2
60+
}
61+
}
62+
}
63+
}
64+
}
65+
input {
66+
name: "block_shape"
67+
type {
68+
tensor_type {
69+
elem_type: 7
70+
shape {
71+
dim {
72+
dim_value: 2
73+
}
74+
}
75+
}
76+
}
77+
}
78+
output {
79+
name: "output"
80+
type {
81+
tensor_type {
82+
elem_type: 1
83+
shape {
84+
dim {
85+
dim_value: 2
86+
}
87+
dim {
88+
dim_value: 1
89+
}
90+
dim {
91+
dim_value: 3
92+
}
93+
dim {
94+
dim_value: 3
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
opset_import {
102+
version: 18
103+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
ir_version: 8
2+
producer_name: "OpenVINO ONNX Frontend"
3+
graph {
4+
node {
5+
input: "input"
6+
input: "image_shape"
7+
input: "block_shape"
8+
output: "output"
9+
name: "col2im_2D_channel_opset_18"
10+
op_type: "Col2Im"
11+
attribute {
12+
name: "dilations"
13+
ints: 1
14+
ints: 1
15+
type: INTS
16+
}
17+
attribute {
18+
name: "pads"
19+
ints: 0
20+
ints: 0
21+
ints: 0
22+
ints: 0
23+
type: INTS
24+
}
25+
attribute {
26+
name: "strides"
27+
ints: 1
28+
ints: 1
29+
type: INTS
30+
}
31+
}
32+
name: "col2im_2D_channel_opset_18"
33+
input {
34+
name: "input"
35+
type {
36+
tensor_type {
37+
elem_type: 1
38+
shape {
39+
dim {
40+
dim_value: 1
41+
}
42+
dim {
43+
dim_value: 12
44+
}
45+
dim {
46+
dim_value: 4
47+
}
48+
}
49+
}
50+
}
51+
}
52+
input {
53+
name: "image_shape"
54+
type {
55+
tensor_type {
56+
elem_type: 7
57+
shape {
58+
dim {
59+
dim_value: 2
60+
}
61+
}
62+
}
63+
}
64+
}
65+
input {
66+
name: "block_shape"
67+
type {
68+
tensor_type {
69+
elem_type: 7
70+
shape {
71+
dim {
72+
dim_value: 2
73+
}
74+
}
75+
}
76+
}
77+
}
78+
output {
79+
name: "output"
80+
type {
81+
tensor_type {
82+
elem_type: 1
83+
shape {
84+
dim {
85+
dim_value: 1
86+
}
87+
dim {
88+
dim_value: 3
89+
}
90+
dim {
91+
dim_value: 3
92+
}
93+
dim {
94+
dim_value: 3
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
opset_import {
102+
version: 18
103+
}

0 commit comments

Comments
 (0)