Skip to content

Commit

Permalink
[ONNX] Use ov::v12::pad in ONNX FE Pad (openvinotoolkit#18460)
Browse files Browse the repository at this point in the history
* Update ONNX FE Pad to use Pad-12

* Add negative pads test

* Use default_opset(opset12) for Pad
  • Loading branch information
mitruska authored Jul 17, 2023
1 parent a5880ee commit 019723a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/frontends/onnx/frontend/src/op/pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "ngraph/shape.hpp"
#include "onnx_import/core/null_node.hpp"
#include "op/pad.hpp"
#include "openvino/opsets/opset11.hpp"
#include "utils/convpool.hpp"
#include "utils/reshape.hpp"

Expand Down Expand Up @@ -56,7 +55,7 @@ OutputVector pad(const Node& node) {
ngraph::CoordinateDiff padding_below = paddings.first;
ngraph::CoordinateDiff padding_above = paddings.second;

return {std::make_shared<ov::opset11::Pad>(
return {std::make_shared<default_opset::Pad>(
data,
std::make_shared<default_opset::Constant>(element::i64, ngraph::Shape{padding_below.size()}, padding_below),
std::make_shared<default_opset::Constant>(element::i64, ngraph::Shape{padding_above.size()}, padding_above),
Expand Down Expand Up @@ -100,7 +99,7 @@ OutputVector pad(const Node& node) {
const std::string mode = node.get_attribute_value<std::string>("mode", "constant");
ngraph::op::PadMode pad_mode = get_pad_mode(mode);

return {std::make_shared<ov::opset11::Pad>(data, padding_begin, padding_end, values, pad_mode)};
return {std::make_shared<default_opset::Pad>(data, padding_begin, padding_end, values, pad_mode)};
}

} // namespace set_11
Expand Down
65 changes: 65 additions & 0 deletions src/frontends/onnx/tests/models/pad_negative_begin_end.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ir_version: 8
producer_name: "onnx-frontend-test"
graph {
node {
input: "x"
input: "pads"
output: "Y"
op_type: "Pad"
attribute {
name: "mode"
s: "constant"
type: STRING
}
}
name: "test-model"
input {
name: "x"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "pads"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 4
}
}
}
}
}
output {
name: "Y"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: -1
}
dim {
dim_value: -1
}
}
}
}
}
}
opset_import {
domain: ""
version: 18
}
13 changes: 13 additions & 0 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3542,6 +3542,19 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pad_optional_constant) {
test_case.run();
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pad_constant_negative_begin_end) {
const auto function = onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
SERIALIZED_ZOO,
"onnx/pad_negative_begin_end.onnx"));
auto test_case = test::TestCase(function, s_device);

test_case.add_input<int32_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
test_case.add_input<int64_t>({-1, -1, -1, -1});
test_case.add_expected_output<int32_t>(Shape{1, 2}, {6, 7});

test_case.run();
}

NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pow_float32_float32) {
const auto function = onnx_import::import_onnx_model(file_util::path_join(CommonTestUtils::getExecutableDirectory(),
SERIALIZED_ZOO,
Expand Down

0 comments on commit 019723a

Please sign in to comment.