From 019723a05d71ac9b5bc181a71fa8a44cb4fe81b2 Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Mon, 17 Jul 2023 15:02:45 +0200 Subject: [PATCH] [ONNX] Use ov::v12::pad in ONNX FE Pad (#18460) * Update ONNX FE Pad to use Pad-12 * Add negative pads test * Use default_opset(opset12) for Pad --- src/frontends/onnx/frontend/src/op/pad.cpp | 5 +- .../models/pad_negative_begin_end.prototxt | 65 +++++++++++++++++++ src/frontends/onnx/tests/onnx_import.in.cpp | 13 ++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/frontends/onnx/tests/models/pad_negative_begin_end.prototxt diff --git a/src/frontends/onnx/frontend/src/op/pad.cpp b/src/frontends/onnx/frontend/src/op/pad.cpp index a84c8bd6867..aa26a8da2be 100644 --- a/src/frontends/onnx/frontend/src/op/pad.cpp +++ b/src/frontends/onnx/frontend/src/op/pad.cpp @@ -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" @@ -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( + return {std::make_shared( data, std::make_shared(element::i64, ngraph::Shape{padding_below.size()}, padding_below), std::make_shared(element::i64, ngraph::Shape{padding_above.size()}, padding_above), @@ -100,7 +99,7 @@ OutputVector pad(const Node& node) { const std::string mode = node.get_attribute_value("mode", "constant"); ngraph::op::PadMode pad_mode = get_pad_mode(mode); - return {std::make_shared(data, padding_begin, padding_end, values, pad_mode)}; + return {std::make_shared(data, padding_begin, padding_end, values, pad_mode)}; } } // namespace set_11 diff --git a/src/frontends/onnx/tests/models/pad_negative_begin_end.prototxt b/src/frontends/onnx/tests/models/pad_negative_begin_end.prototxt new file mode 100644 index 00000000000..5b3124e939b --- /dev/null +++ b/src/frontends/onnx/tests/models/pad_negative_begin_end.prototxt @@ -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 +} diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 609a74a113f..df1caca387a 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -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({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); + test_case.add_input({-1, -1, -1, -1}); + test_case.add_expected_output(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,