From 3febe4719a686f38037c17c08c9bc17449f1391f Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Tue, 21 Feb 2023 04:02:08 +0800 Subject: [PATCH 1/8] add flip op --- src/frontends/paddle/src/op/flip.cpp | 42 ++++++++++++ src/frontends/paddle/src/op_table.cpp | 2 + src/frontends/paddle/tests/op_fuzzy.cpp | 6 ++ .../test_models/gen_scripts/generate_flip.py | 65 +++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 src/frontends/paddle/src/op/flip.cpp create mode 100644 src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp new file mode 100644 index 00000000000000..ba2b6778bd928b --- /dev/null +++ b/src/frontends/paddle/src/op/flip.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "default_opset.hpp" +#include "openvino/frontend/paddle/node_context.hpp" + +namespace ov { +namespace frontend { +namespace paddle { +namespace op { +NamedOutputs flip(const NodeContext& node) { + const auto data_node = node.get_input("X"); + const auto axes = node.get_attribute>("axis"); + const auto input_shape = data_node.get_partial_shape().get_shape(); + const auto dims = static_cast(data_node.get_partial_shape().rank().get_length()); + // for zero-dim input + PADDLE_OP_CHECK(node, (dims > 0), "Input dims must be greater than 0"); + + Output temp = data_node; + std::vector> temp_split_out; + int32_t axis; + for (int idx = 0; idx < dims; idx++) { + axis = axes[idx]; + if (axis < 0) + axis += dims; + // Do nothing when dims of selected axis are 1. + if (input_shape[axis] != 1) { + const auto split_axes = default_opset::Constant::create(element::i64, Shape{}, {axis}); + auto split = std::make_shared(temp, split_axes, input_shape[axis]); + temp_split_out = split->outputs(); + // reverse the vector then concat + std::reverse(temp_split_out.begin(), temp_split_out.end()); + temp = std::make_shared(temp_split_out, axis); + } + } + return node.default_single_output_mapping({std::make_shared(temp)}, {"Out"}); +} +} // namespace op +} // namespace paddle +} // namespace frontend +} // namespace ov diff --git a/src/frontends/paddle/src/op_table.cpp b/src/frontends/paddle/src/op_table.cpp index cd58f3fed220a8..fe5f97e85f2c0d 100644 --- a/src/frontends/paddle/src/op_table.cpp +++ b/src/frontends/paddle/src/op_table.cpp @@ -40,6 +40,7 @@ OP_CONVERTER(elementwise_sub); OP_CONVERTER(embedding); OP_CONVERTER(exp); OP_CONVERTER(expand_v2); +OP_CONVERTER(flip); OP_CONVERTER(fill_any_like); OP_CONVERTER(fill_constant_batch_size_like); OP_CONVERTER(fill_constant); @@ -152,6 +153,7 @@ std::map get_supported_ops() { {"fill_constant_batch_size_like", op::fill_constant_batch_size_like}, {"fill_constant", op::fill_constant}, {"flatten_contiguous_range", op::flatten_contiguous_range}, + {"flip", op::flip}, {"floor", op::floor}, {"gather", op::gather}, {"gather_nd", op::gather_nd}, diff --git a/src/frontends/paddle/tests/op_fuzzy.cpp b/src/frontends/paddle/tests/op_fuzzy.cpp index ef742b2064b2f9..d1de45bd473546 100644 --- a/src/frontends/paddle/tests/op_fuzzy.cpp +++ b/src/frontends/paddle/tests/op_fuzzy.cpp @@ -189,6 +189,12 @@ static const std::vector models{ std::string("expand_v2_tensor_list"), std::string("expand_v2_tensor_list2"), std::string("exp_test_float32"), + std::string("flip_1"), + std::string("flip_2"), + std::string("flip_3"), + std::string("flip_4"), + std::string("flip_5"), + std::string("flip_6"), std::string("fill_any_like"), std::string("fill_any_like_f16"), std::string("fill_any_like_f32"), diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py new file mode 100644 index 00000000000000..4ca96b06ac7375 --- /dev/null +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py @@ -0,0 +1,65 @@ +# +# flip paddle model generator +# +import numpy as np +from save_model import saveModel +import paddle +import sys + + +def flip(name: str, x, axis): + paddle.enable_static() + + with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): + data = paddle.static.data(name='x', shape=x.shape, dtype=x.dtype) + out = paddle.flip(data, axis=axis) + + cpu = paddle.static.cpu_places(1) + exe = paddle.static.Executor(cpu[0]) + # startup program will call initializer to initialize the parameters. + exe.run(paddle.static.default_startup_program()) + + outs = exe.run( + feed={'x': x}, + fetch_list=[out]) + + saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[ + x], outputs=[outs[0]], target_dir=sys.argv[1]) + + return outs[0] + + +def main(): + data_type = 'int32' + axis = [2, 3] + x = np.random.randint(0, 5, (2, 3, 4, 5)).astype(data_type) + flip("flip_1", x, axis) + + data_type = 'float32' + axis = [-1, -3] + x = np.random.randn(3, 2, 1, 5).astype(data_type) + flip("flip_2", x, axis) + + data_type = 'bool' + axis = [0, -2] + x = np.random.randint(0, 1, (1, 2, 4, 3)).astype(data_type) + flip("flip_3", x, axis) + + data_type = 'float32' + axis = [0, 1] + x = np.random.randn(1, 1, 1, 1).astype(data_type) + flip("flip_4", x, axis) + + data_type = 'float64' + axis = 1 + x = np.random.randn(5, 3, 1, 1).astype(data_type) + flip("flip_5", x, axis) + + data_type = 'float32' + axis = 0 + x = np.random.randn(1).astype(data_type) + flip("flip_6", x, axis) + + +if __name__ == "__main__": + main() From 0e171a7b1374a4337dbca34979b9487ab7f96947 Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Tue, 21 Feb 2023 18:52:14 +0800 Subject: [PATCH 2/8] fix --- src/frontends/paddle/src/op/flip.cpp | 6 ++++-- src/frontends/paddle/tests/op_fuzzy.cpp | 1 - .../test_models/gen_scripts/generate_flip.py | 17 ++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index ba2b6778bd928b..51e8079d50a59b 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -14,13 +14,14 @@ NamedOutputs flip(const NodeContext& node) { const auto axes = node.get_attribute>("axis"); const auto input_shape = data_node.get_partial_shape().get_shape(); const auto dims = static_cast(data_node.get_partial_shape().rank().get_length()); + const auto dtype = data_node.get_element_type(); // for zero-dim input PADDLE_OP_CHECK(node, (dims > 0), "Input dims must be greater than 0"); Output temp = data_node; std::vector> temp_split_out; int32_t axis; - for (int idx = 0; idx < dims; idx++) { + for (int idx = 0; idx < axes.size(); idx++) { axis = axes[idx]; if (axis < 0) axis += dims; @@ -34,7 +35,8 @@ NamedOutputs flip(const NodeContext& node) { temp = std::make_shared(temp_split_out, axis); } } - return node.default_single_output_mapping({std::make_shared(temp)}, {"Out"}); + // for output, convert Output to shared_ptr + return node.default_single_output_mapping({std::make_shared(temp, dtype)}, {"Out"}); } } // namespace op } // namespace paddle diff --git a/src/frontends/paddle/tests/op_fuzzy.cpp b/src/frontends/paddle/tests/op_fuzzy.cpp index d1de45bd473546..2c28482b28a61b 100644 --- a/src/frontends/paddle/tests/op_fuzzy.cpp +++ b/src/frontends/paddle/tests/op_fuzzy.cpp @@ -194,7 +194,6 @@ static const std::vector models{ std::string("flip_3"), std::string("flip_4"), std::string("flip_5"), - std::string("flip_6"), std::string("fill_any_like"), std::string("fill_any_like_f16"), std::string("fill_any_like_f32"), diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py index 4ca96b06ac7375..d1cb7de184ef16 100644 --- a/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py @@ -40,25 +40,20 @@ def main(): x = np.random.randn(3, 2, 1, 5).astype(data_type) flip("flip_2", x, axis) - data_type = 'bool' - axis = [0, -2] - x = np.random.randint(0, 1, (1, 2, 4, 3)).astype(data_type) - flip("flip_3", x, axis) - data_type = 'float32' axis = [0, 1] x = np.random.randn(1, 1, 1, 1).astype(data_type) - flip("flip_4", x, axis) + flip("flip_3", x, axis) - data_type = 'float64' + data_type = 'int64' axis = 1 - x = np.random.randn(5, 3, 1, 1).astype(data_type) - flip("flip_5", x, axis) + x = np.random.randint(-1, 3, (5, 3, 1, 1)).astype(data_type) + flip("flip_4", x, axis) data_type = 'float32' - axis = 0 + axis = -1 x = np.random.randn(1).astype(data_type) - flip("flip_6", x, axis) + flip("flip_5", x, axis) if __name__ == "__main__": From cfc5d4293349325d81bf9d56110677cb578e779f Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Tue, 21 Feb 2023 20:23:05 +0800 Subject: [PATCH 3/8] fix signedness error --- src/frontends/paddle/src/op/flip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index 51e8079d50a59b..876462a4febeae 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -21,7 +21,7 @@ NamedOutputs flip(const NodeContext& node) { Output temp = data_node; std::vector> temp_split_out; int32_t axis; - for (int idx = 0; idx < axes.size(); idx++) { + for (size_t idx = 0; idx < axes.size(); idx++) { axis = axes[idx]; if (axis < 0) axis += dims; From 4987fabc7fa034c66f14300392ca6d02a2fb37c1 Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Thu, 2 Mar 2023 12:48:59 +0800 Subject: [PATCH 4/8] update flip --- src/frontends/paddle/src/op/flip.cpp | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index 876462a4febeae..5213e11e34cdd8 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -12,33 +12,35 @@ namespace op { NamedOutputs flip(const NodeContext& node) { const auto data_node = node.get_input("X"); const auto axes = node.get_attribute>("axis"); - const auto input_shape = data_node.get_partial_shape().get_shape(); + auto input_shape = data_node.get_partial_shape(); + PADDLE_OP_CHECK(node, (input_shape.rank().is_static()), "flip not support dynamic rank!"); const auto dims = static_cast(data_node.get_partial_shape().rank().get_length()); const auto dtype = data_node.get_element_type(); - // for zero-dim input - PADDLE_OP_CHECK(node, (dims > 0), "Input dims must be greater than 0"); - + bool is_1dim = false; + int32_t axis, shape_len, batch_index; Output temp = data_node; - std::vector> temp_split_out; - int32_t axis; + const auto uns_axes = default_opset::Constant::create(ov::element::i64, {1}, {1}); + if (dims == 1) { + temp = std::make_shared(temp, uns_axes); + input_shape = temp.get_partial_shape(); + is_1dim = true; + } for (size_t idx = 0; idx < axes.size(); idx++) { axis = axes[idx]; - if (axis < 0) - axis += dims; - // Do nothing when dims of selected axis are 1. - if (input_shape[axis] != 1) { - const auto split_axes = default_opset::Constant::create(element::i64, Shape{}, {axis}); - auto split = std::make_shared(temp, split_axes, input_shape[axis]); - temp_split_out = split->outputs(); - // reverse the vector then concat - std::reverse(temp_split_out.begin(), temp_split_out.end()); - temp = std::make_shared(temp_split_out, axis); - } + axis += axis < 0 ? dims : 0; + shape_len = input_shape[axis].get_length(); + batch_index = axis == 0 ? 1 : 0; + auto batch_len = input_shape[batch_index].get_length(); + const auto seq_length = + default_opset::Constant::create(element::i64, {static_cast(batch_len)}, {shape_len}); + temp = std::make_shared(temp, seq_length, batch_index, axis); } + if (is_1dim) + return node.default_single_output_mapping({std::make_shared(temp, uns_axes)}, {"Out"}); // for output, convert Output to shared_ptr return node.default_single_output_mapping({std::make_shared(temp, dtype)}, {"Out"}); } } // namespace op } // namespace paddle } // namespace frontend -} // namespace ov +} // namespace ov \ No newline at end of file From 501481cebb6826703c30fe37ef9f32f4ae09f468 Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Sat, 4 Mar 2023 14:27:15 +0800 Subject: [PATCH 5/8] use Slice --- src/frontends/paddle/src/op/flip.cpp | 47 ++++++++----------- src/frontends/paddle/tests/op_fuzzy.cpp | 2 + .../test_models/gen_scripts/generate_flip.py | 17 ++++++- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index 5213e11e34cdd8..267389a1893d25 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -5,6 +5,8 @@ #include "default_opset.hpp" #include "openvino/frontend/paddle/node_context.hpp" +#define out(a) std::cout << a << std::endl; + namespace ov { namespace frontend { namespace paddle { @@ -12,35 +14,24 @@ namespace op { NamedOutputs flip(const NodeContext& node) { const auto data_node = node.get_input("X"); const auto axes = node.get_attribute>("axis"); - auto input_shape = data_node.get_partial_shape(); - PADDLE_OP_CHECK(node, (input_shape.rank().is_static()), "flip not support dynamic rank!"); - const auto dims = static_cast(data_node.get_partial_shape().rank().get_length()); - const auto dtype = data_node.get_element_type(); - bool is_1dim = false; - int32_t axis, shape_len, batch_index; - Output temp = data_node; - const auto uns_axes = default_opset::Constant::create(ov::element::i64, {1}, {1}); - if (dims == 1) { - temp = std::make_shared(temp, uns_axes); - input_shape = temp.get_partial_shape(); - is_1dim = true; - } - for (size_t idx = 0; idx < axes.size(); idx++) { - axis = axes[idx]; - axis += axis < 0 ? dims : 0; - shape_len = input_shape[axis].get_length(); - batch_index = axis == 0 ? 1 : 0; - auto batch_len = input_shape[batch_index].get_length(); - const auto seq_length = - default_opset::Constant::create(element::i64, {static_cast(batch_len)}, {shape_len}); - temp = std::make_shared(temp, seq_length, batch_index, axis); - } - if (is_1dim) - return node.default_single_output_mapping({std::make_shared(temp, uns_axes)}, {"Out"}); - // for output, convert Output to shared_ptr - return node.default_single_output_mapping({std::make_shared(temp, dtype)}, {"Out"}); + auto axes_length = axes.size(); + const auto starts = + default_opset::Constant::create(element::i32, + {axes_length}, + std::vector(axes_length, std::numeric_limits::max())); + const auto stops = + default_opset::Constant::create(element::i32, + {axes_length}, + std::vector(axes_length, std::numeric_limits::min())); + const auto steps = + default_opset::Constant::create(element::i32, {axes_length}, std::vector(axes_length, -1)); + const auto axes_node = default_opset::Constant::create(element::i32, {axes_length}, axes); + + return node.default_single_output_mapping( + {std::make_shared(data_node, starts, stops, steps, axes_node)}, + {"Out"}); } } // namespace op } // namespace paddle } // namespace frontend -} // namespace ov \ No newline at end of file +} // namespace ov diff --git a/src/frontends/paddle/tests/op_fuzzy.cpp b/src/frontends/paddle/tests/op_fuzzy.cpp index 9b8166ec52f773..d71f7098aece31 100644 --- a/src/frontends/paddle/tests/op_fuzzy.cpp +++ b/src/frontends/paddle/tests/op_fuzzy.cpp @@ -195,6 +195,8 @@ static const std::vector models{ std::string("flip_3"), std::string("flip_4"), std::string("flip_5"), + std::string("flip_dynamic_1"), + std::string("flip_dynamic_2"), std::string("fill_any_like"), std::string("fill_any_like_f16"), std::string("fill_any_like_f32"), diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py index d1cb7de184ef16..5c91c0bf5f3603 100644 --- a/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.py @@ -7,11 +7,14 @@ import sys -def flip(name: str, x, axis): +def flip(name: str, x, axis, is_dynamic=False): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): - data = paddle.static.data(name='x', shape=x.shape, dtype=x.dtype) + if is_dynamic: + data = paddle.static.data(name='x', shape=(-1, ) * len(x.shape), dtype=x.dtype) + else: + data = paddle.static.data(name='x', shape=x.shape, dtype=x.dtype) out = paddle.flip(data, axis=axis) cpu = paddle.static.cpu_places(1) @@ -37,6 +40,7 @@ def main(): data_type = 'float32' axis = [-1, -3] + # axis = [3, 1] x = np.random.randn(3, 2, 1, 5).astype(data_type) flip("flip_2", x, axis) @@ -55,6 +59,15 @@ def main(): x = np.random.randn(1).astype(data_type) flip("flip_5", x, axis) + data_type = 'int64' + axis = 3 + x = np.random.randint(-5, 5, (1, 1, 4, 1)).astype(data_type) + flip("flip_dynamic_1", x, axis, True) + + data_type = 'float32' + axis = [-1, -2] + x = np.random.randn(1, 4, 1).astype(data_type) + flip("flip_dynamic_2", x, axis, True) if __name__ == "__main__": main() From 2f3e5c8a8a6aba53019b079569183e27fd66d6cc Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Mon, 6 Mar 2023 11:38:56 +0800 Subject: [PATCH 6/8] remove redundant codes --- src/frontends/paddle/src/op/flip.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index 267389a1893d25..e8d5d22db83b9e 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -5,8 +5,6 @@ #include "default_opset.hpp" #include "openvino/frontend/paddle/node_context.hpp" -#define out(a) std::cout << a << std::endl; - namespace ov { namespace frontend { namespace paddle { From d549f63e5e7e7ae41c65768603f29215a9f9d3b3 Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Thu, 18 May 2023 18:40:19 +0800 Subject: [PATCH 7/8] unify flip and reverse --- src/frontends/paddle/src/op/flip.cpp | 22 ++------------ src/frontends/paddle/src/op/reverse.cpp | 22 ++------------ src/frontends/paddle/src/op/reverse_op.hpp | 35 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 src/frontends/paddle/src/op/reverse_op.hpp diff --git a/src/frontends/paddle/src/op/flip.cpp b/src/frontends/paddle/src/op/flip.cpp index e8d5d22db83b9e..804edcc7e015d7 100644 --- a/src/frontends/paddle/src/op/flip.cpp +++ b/src/frontends/paddle/src/op/flip.cpp @@ -2,32 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "default_opset.hpp" -#include "openvino/frontend/paddle/node_context.hpp" +#include "reverse_op.hpp" namespace ov { namespace frontend { namespace paddle { namespace op { NamedOutputs flip(const NodeContext& node) { - const auto data_node = node.get_input("X"); - const auto axes = node.get_attribute>("axis"); - auto axes_length = axes.size(); - const auto starts = - default_opset::Constant::create(element::i32, - {axes_length}, - std::vector(axes_length, std::numeric_limits::max())); - const auto stops = - default_opset::Constant::create(element::i32, - {axes_length}, - std::vector(axes_length, std::numeric_limits::min())); - const auto steps = - default_opset::Constant::create(element::i32, {axes_length}, std::vector(axes_length, -1)); - const auto axes_node = default_opset::Constant::create(element::i32, {axes_length}, axes); - - return node.default_single_output_mapping( - {std::make_shared(data_node, starts, stops, steps, axes_node)}, - {"Out"}); + return reverse_op(node); } } // namespace op } // namespace paddle diff --git a/src/frontends/paddle/src/op/reverse.cpp b/src/frontends/paddle/src/op/reverse.cpp index b5e87f4c5b9fca..097e13b401986b 100644 --- a/src/frontends/paddle/src/op/reverse.cpp +++ b/src/frontends/paddle/src/op/reverse.cpp @@ -2,32 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "default_opset.hpp" -#include "openvino/frontend/paddle/node_context.hpp" -#include "openvino/opsets/opset1.hpp" +#include "reverse_op.hpp" namespace ov { namespace frontend { namespace paddle { namespace op { - -using namespace default_opset; - NamedOutputs reverse(const NodeContext& node) { - auto x = node.get_input("X"); - // axis is a vector - auto axis = node.get_attribute>("axis"); - // try to keep the axis positive since reverse IR doesn't support negative axis. - const auto dims = static_cast(x.get_partial_shape().rank().get_length()); - std::for_each(axis.begin(), axis.end(), [&dims](int32_t& value) { - if (value < 0) { - value += dims; - } - }); - - auto axis_node = std::make_shared(ngraph::element::i32, Shape{axis.size()}, axis); - auto reverse_op = std::make_shared(x, axis_node, ov::opset1::Reverse::Mode::INDEX); - return node.default_single_output_mapping({reverse_op}, {"Out"}); + return reverse_op(node); } } // namespace op } // namespace paddle diff --git a/src/frontends/paddle/src/op/reverse_op.hpp b/src/frontends/paddle/src/op/reverse_op.hpp new file mode 100644 index 00000000000000..0b9bde4681f0ce --- /dev/null +++ b/src/frontends/paddle/src/op/reverse_op.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "default_opset.hpp" +#include "openvino/frontend/paddle/node_context.hpp" + +namespace ov { +namespace frontend { +namespace paddle { +namespace op { +NamedOutputs reverse_op(const NodeContext& node) { + const auto data_node = node.get_input("X"); + const auto axes = node.get_attribute>("axis"); + auto axes_length = axes.size(); + const auto starts = + default_opset::Constant::create(element::i32, + {axes_length}, + std::vector(axes_length, std::numeric_limits::max())); + const auto stops = + default_opset::Constant::create(element::i32, + {axes_length}, + std::vector(axes_length, std::numeric_limits::min())); + const auto steps = + default_opset::Constant::create(element::i32, {axes_length}, std::vector(axes_length, -1)); + const auto axes_node = default_opset::Constant::create(element::i32, {axes_length}, axes); + + return node.default_single_output_mapping( + {std::make_shared(data_node, starts, stops, steps, axes_node)}, + {"Out"}); +} +} // namespace op +} // namespace paddle +} // namespace frontend +} // namespace ov From a9756004f2bb84c410ff41984df763afa28107b7 Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <1186454801@qq.com> Date: Fri, 19 May 2023 12:39:11 +0800 Subject: [PATCH 8/8] fix bug --- src/frontends/paddle/src/op/reverse_op.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/frontends/paddle/src/op/reverse_op.hpp b/src/frontends/paddle/src/op/reverse_op.hpp index 0b9bde4681f0ce..eec1afb1dd9986 100644 --- a/src/frontends/paddle/src/op/reverse_op.hpp +++ b/src/frontends/paddle/src/op/reverse_op.hpp @@ -1,6 +1,7 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // +#pragma once #include "default_opset.hpp" #include "openvino/frontend/paddle/node_context.hpp" @@ -9,6 +10,7 @@ namespace ov { namespace frontend { namespace paddle { namespace op { +namespace { NamedOutputs reverse_op(const NodeContext& node) { const auto data_node = node.get_input("X"); const auto axes = node.get_attribute>("axis"); @@ -29,6 +31,7 @@ NamedOutputs reverse_op(const NodeContext& node) { {std::make_shared(data_node, starts, stops, steps, axes_node)}, {"Out"}); } +} // namespace } // namespace op } // namespace paddle } // namespace frontend