From 1d563acdc9477ff787d89f1189e288e13cf78f55 Mon Sep 17 00:00:00 2001 From: Xiuchuan Zhai Date: Sat, 13 May 2023 13:53:16 +0800 Subject: [PATCH] enable sin and cos in PDFE --- .../Supported_Frameworks_Layers.md | 2 + src/frontends/paddle/src/op/cos.cpp | 19 +++++++++ src/frontends/paddle/src/op/sin.cpp | 19 +++++++++ src/frontends/paddle/src/op_table.cpp | 4 ++ src/frontends/paddle/tests/op_fuzzy.cpp | 2 + .../test_models/gen_scripts/generate_cos.py | 40 +++++++++++++++++++ .../test_models/gen_scripts/generate_sin.py | 40 +++++++++++++++++++ 7 files changed, 126 insertions(+) create mode 100644 src/frontends/paddle/src/op/cos.cpp create mode 100644 src/frontends/paddle/src/op/sin.cpp create mode 100644 src/frontends/paddle/tests/test_models/gen_scripts/generate_cos.py create mode 100644 src/frontends/paddle/tests/test_models/gen_scripts/generate_sin.py diff --git a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md index a23a78daa5f2ce..00ef6267f77d6d 100644 --- a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md +++ b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md @@ -687,6 +687,7 @@ paddlepaddle>=2.1 | conditional_block | | | conv2d | `NHWC` data_layout is not supported. | | conv2d_transpose | | +| cos | | | cumsum | | | deformable_conv | | | depthwise_conv2d | `NHWC` data_layout is not supported. | @@ -755,6 +756,7 @@ paddlepaddle>=2.1 | select_input | | | shape | | | sigmoid | | +| sin | | | slice | | | softmax | | | softplus | | diff --git a/src/frontends/paddle/src/op/cos.cpp b/src/frontends/paddle/src/op/cos.cpp new file mode 100644 index 00000000000000..0134de7d790bd0 --- /dev/null +++ b/src/frontends/paddle/src/op/cos.cpp @@ -0,0 +1,19 @@ +// 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 cos(const NodeContext& node) { + return node.default_single_output_mapping({std::make_shared(node.get_input("X"))}, {"Out"}); +} + +} // namespace op +} // namespace paddle +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/paddle/src/op/sin.cpp b/src/frontends/paddle/src/op/sin.cpp new file mode 100644 index 00000000000000..ae0de18f5d8a39 --- /dev/null +++ b/src/frontends/paddle/src/op/sin.cpp @@ -0,0 +1,19 @@ +// 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 sin(const NodeContext& node) { + return node.default_single_output_mapping({std::make_shared(node.get_input("X"))}, {"Out"}); +} + +} // namespace op +} // namespace paddle +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/paddle/src/op_table.cpp b/src/frontends/paddle/src/op_table.cpp index 0a21af065b98ad..6589a7d933e15c 100644 --- a/src/frontends/paddle/src/op_table.cpp +++ b/src/frontends/paddle/src/op_table.cpp @@ -22,6 +22,7 @@ OP_CONVERTER(concat); OP_CONVERTER(conditional_block); OP_CONVERTER(conv2d); OP_CONVERTER(conv2d_transpose); +OP_CONVERTER(cos); OP_CONVERTER(cumsum); OP_CONVERTER(deformable_conv); OP_CONVERTER(dequantize_linear); @@ -94,6 +95,7 @@ OP_CONVERTER(slice); OP_CONVERTER(softmax); OP_CONVERTER(softplus); OP_CONVERTER(sigmoid); +OP_CONVERTER(sin); OP_CONVERTER(split); OP_CONVERTER(sqrt); OP_CONVERTER(squeeze); @@ -132,6 +134,7 @@ std::map get_supported_ops() { {"conditional_block", op::conditional_block}, {"conv2d", op::conv2d}, {"conv2d_transpose", op::conv2d_transpose}, + {"cos", op::cos}, {"cumsum", op::cumsum}, {"deformable_conv", op::deformable_conv}, {"deformable_conv_v1", op::deformable_conv}, @@ -210,6 +213,7 @@ std::map get_supported_ops() { {"softmax", op::softmax}, {"softplus", op::softplus}, {"sigmoid", op::sigmoid}, + {"sin", op::sin}, {"split", op::split}, {"sqrt", op::sqrt}, {"squeeze2", op::squeeze}, diff --git a/src/frontends/paddle/tests/op_fuzzy.cpp b/src/frontends/paddle/tests/op_fuzzy.cpp index 598b49dc41a548..70ed2af7f9b553 100644 --- a/src/frontends/paddle/tests/op_fuzzy.cpp +++ b/src/frontends/paddle/tests/op_fuzzy.cpp @@ -114,6 +114,7 @@ static const std::vector models{ std::string("conv2d_transpose_strides_padding/conv2d_transpose_strides_padding.pdmodel"), std::string("conv2d_transpose_VALID_padding/conv2d_transpose_VALID_padding.pdmodel"), std::string("conv2d_VALID_padding/conv2d_VALID_padding.pdmodel"), + std::string("cos"), std::string("cumsum"), std::string("cumsum_i32"), std::string("cumsum_i64"), @@ -448,6 +449,7 @@ static const std::vector models{ std::string("scale_tensor_bias_before"), std::string("shape"), std::string("sigmoid"), + std::string("sin"), std::string("slice"), std::string("slice_1d"), std::string("slice_decrease_axis/slice_decrease_axis.pdmodel"), diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_cos.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_cos.py new file mode 100644 index 00000000000000..4ae9267ad5745a --- /dev/null +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_cos.py @@ -0,0 +1,40 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# +# tanh paddle model generator +# +import numpy as np +from save_model import saveModel +import paddle +import sys + +data_type = 'float32' + +def cos(name:str, x): + paddle.enable_static() + + with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): + data = paddle.static.data(name='x', shape=x.shape, dtype = data_type) + out = paddle.sin(data) + + 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(): + x = np.random.rand(8, 24, 32).astype(data_type) + + cos("cos", x) + +if __name__ == "__main__": + main() diff --git a/src/frontends/paddle/tests/test_models/gen_scripts/generate_sin.py b/src/frontends/paddle/tests/test_models/gen_scripts/generate_sin.py new file mode 100644 index 00000000000000..2495b49ded1905 --- /dev/null +++ b/src/frontends/paddle/tests/test_models/gen_scripts/generate_sin.py @@ -0,0 +1,40 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# +# tanh paddle model generator +# +import numpy as np +from save_model import saveModel +import paddle +import sys + +data_type = 'float32' + +def sin(name:str, x): + paddle.enable_static() + + with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): + data = paddle.static.data(name='x', shape=x.shape, dtype = data_type) + out = paddle.sin(data) + + 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(): + x = np.random.rand(8, 24, 32).astype(data_type) + + sin("sin", x) + +if __name__ == "__main__": + main()