From 1e6214863b294ed2fffcf0ca3b8ebdf8b7b3f8b3 Mon Sep 17 00:00:00 2001 From: Luo Cheng Date: Wed, 12 May 2021 09:47:25 +0800 Subject: [PATCH] add expand_v2 support (#18) --- .../paddlepaddle/src/op/expand_v2.cpp | 39 ++++++++++++++++++ .../paddlepaddle/src/op/expand_v2.hpp | 27 ++++++++++++ ngraph/frontend/paddlepaddle/src/op_table.cpp | 5 ++- .../gen_scripts/generate_expand_v2.py | 36 ++++++++++++++++ .../paddlepaddle/models/expand_v2/__model__ | Bin 0 -> 12842 bytes .../models/expand_v2/expand_v2.pdmodel | Bin 0 -> 13046 bytes .../paddlepaddle/models/expand_v2/input0.npy | Bin 0 -> 152 bytes .../models/expand_v2/input0.x.float32.npy | Bin 0 -> 152 bytes .../paddlepaddle/models/expand_v2/output0.npy | Bin 0 -> 272 bytes .../test/files/paddlepaddle/models/models.csv | 1 + 10 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp create mode 100644 ngraph/frontend/paddlepaddle/src/op/expand_v2.hpp create mode 100644 ngraph/test/files/paddlepaddle/gen_scripts/generate_expand_v2.py create mode 100644 ngraph/test/files/paddlepaddle/models/expand_v2/__model__ create mode 100644 ngraph/test/files/paddlepaddle/models/expand_v2/expand_v2.pdmodel create mode 100644 ngraph/test/files/paddlepaddle/models/expand_v2/input0.npy create mode 100644 ngraph/test/files/paddlepaddle/models/expand_v2/input0.x.float32.npy create mode 100644 ngraph/test/files/paddlepaddle/models/expand_v2/output0.npy diff --git a/ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp b/ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp new file mode 100644 index 00000000000000..ddb4f4113438a6 --- /dev/null +++ b/ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp @@ -0,0 +1,39 @@ +//***************************************************************************** +// Copyright 2017-2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include +#include "expand_v2.hpp" +#include + +namespace ngraph { +namespace frontend { +namespace pdpd { +namespace op { + +NamedOutputs expand_v2 (const NodeContext& node) { + auto x = node.get_ng_input("X"); + std::vector shapeExpected; + if (node.has_attribute>("shape")) { + shapeExpected = node.get_attribute>("shape"); + } else { + throw std::runtime_error("expand: has no shape attribute"); + } + + auto shapeExpectedNode = ngraph::opset6::Constant::create(ngraph::element::i32, {shapeExpected.size()}, shapeExpected); + return node.default_single_output_mapping({std::make_shared(x, shapeExpectedNode)}, {"Out"}); +} + +}}}} \ No newline at end of file diff --git a/ngraph/frontend/paddlepaddle/src/op/expand_v2.hpp b/ngraph/frontend/paddlepaddle/src/op/expand_v2.hpp new file mode 100644 index 00000000000000..29bf14cc80ebaf --- /dev/null +++ b/ngraph/frontend/paddlepaddle/src/op/expand_v2.hpp @@ -0,0 +1,27 @@ +//***************************************************************************** +// Copyright 2017-2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#pragma once +#include "node_context.hpp" + +namespace ngraph { +namespace frontend { +namespace pdpd { +namespace op { + +NamedOutputs expand_v2 (const NodeContext& node); + +}}}} \ No newline at end of file diff --git a/ngraph/frontend/paddlepaddle/src/op_table.cpp b/ngraph/frontend/paddlepaddle/src/op_table.cpp index a8998c67b95ecc..e1a6912704fadf 100644 --- a/ngraph/frontend/paddlepaddle/src/op_table.cpp +++ b/ngraph/frontend/paddlepaddle/src/op_table.cpp @@ -60,7 +60,7 @@ #include "op/logical_not.hpp" #include "op/range.hpp" #include "op_table.hpp" - +#include "op/expand_v2.hpp" namespace ngraph { namespace frontend { @@ -123,7 +123,8 @@ std::map get_supported_ops() { {"conv2d_transpose", op::conv2d_transpose}, {"equal", op::equal}, {"logical_not", op::logical_not}, - {"range", op::range} + {"range", op::range}, + {"expand_v2", op::expand_v2} }; }; diff --git a/ngraph/test/files/paddlepaddle/gen_scripts/generate_expand_v2.py b/ngraph/test/files/paddlepaddle/gen_scripts/generate_expand_v2.py new file mode 100644 index 00000000000000..ecda9eb7c0add8 --- /dev/null +++ b/ngraph/test/files/paddlepaddle/gen_scripts/generate_expand_v2.py @@ -0,0 +1,36 @@ +# +# expand_v2 paddle model generator +# +import numpy as np +from save_model import saveModel +import paddle as pdpd + +data_type = 'float32' + +def expand_v2(name:str, x, shape:list): + pdpd.enable_static() + + with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): + node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) + out = pdpd.expand(node_x, shape=shape, name='expand_v2') + + cpu = pdpd.static.cpu_places(1) + exe = pdpd.static.Executor(cpu[0]) + # startup program will call initializer to initialize the parameters. + exe.run(pdpd.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]]) + + return outs[0] + +def main(): + data = np.random.rand(1, 1, 6).astype(data_type) + + expand_v2("expand_v2", data, [2, 3, 6]) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ngraph/test/files/paddlepaddle/models/expand_v2/__model__ b/ngraph/test/files/paddlepaddle/models/expand_v2/__model__ new file mode 100644 index 0000000000000000000000000000000000000000..1bbb02ab9eb257de3d500d2a355feb5257d54799 GIT binary patch literal 12842 zcmeHOU2hw?6}9Zxv6(MLn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lrOtABpK;6Mcj za*EvKw@Abn9H`(xMQ#$`tS*|6E^?FZYh*}^+~g}#$fpdnlAD};-Z(cm`AE}nWE~q$ zyE!`$R2LObeI9=CvZ}vsjeS+)NXLa2I4UghZt03s$Aosb``DZl3^((BxHu-5g1zF1 zu>76;^ml|)LGXWiL^z{7IFs_cjx4D@L6l3MtgZd>2S}n`>TzG1+qJdo9a7e})bA^t z3T@4;pOsc~t^c?~KGJ88SDY~_SM5>63OaV}pKqa;_*Yz4@iFPmiX|>>|LQm2?EjV!PC$Rj zV}E*H7h`V6w*m;#v~z1`)?6#Klla)wCghSI`s4X^vaJC`+jFdsaeFCVMKPjJ5 RF}8z(=b`ruB0C+{{{?2^a%lhn literal 0 HcmV?d00001 diff --git a/ngraph/test/files/paddlepaddle/models/expand_v2/expand_v2.pdmodel b/ngraph/test/files/paddlepaddle/models/expand_v2/expand_v2.pdmodel new file mode 100644 index 0000000000000000000000000000000000000000..43b66f64ef5ee234c87e1a92350170a02db6caf0 GIT binary patch literal 13046 zcmeHO+in}j85Si=mc}QV@j+IAV8J91Dbrk@EL&;R0$U*MO`8DDMF7JX40ng*fXm(W z&Mrm8Fi`ZW?L{wx7U*RkqmR&s=xg+<{bq(-QWRUomE#)0%7DBxJBNS%!^}7Tej@*P zzP(ob*X*aTcY|#9c;XI9>)T|vuy>tY>2dC%w1d(EQkayA+gDM&y}em1;NMnpZFkKo z?0rmb@kzu2kB(dQWE9ax=_VQy-Eh6QQQX>H+v|{zBpY)of*z0QDD=2*OPBeaHguon z!r;1(8od0w`(%d{z9|_=w#mkqX;Lao_H?;?i|m9E_4ru0ytsa_hKg&bh(nAzW^r+| z{O5b*I%+VFFB9eti<{0Dmi2}3xmC7P8QZ?-+R4=HId0^qEOm%@$^uT*6Bkoq6pS-~oPan@`aG@3FLp3g+aJQn0 zHA_w1_rospW!3p(Asc!Sj=1f+c6}^W!$*?GV;`Y{^h-rvNiPqW$7Ml;rwzcDST1YMJyRq5*GJ) zqP$NgvGIz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b/ngraph/test/files/paddlepaddle/models/expand_v2/input0.npy new file mode 100644 index 0000000000000000000000000000000000000000..495a5f07367c223b9cee61723b7fcc670ac3f628 GIT binary patch literal 152 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= yXCxM+0{I$-ItoB!rm3S)t3V#$+WT6?J~s2Boxl@Kd-tRK_UnrR?H?uD+XDc0Iwg|; literal 0 HcmV?d00001 diff --git a/ngraph/test/files/paddlepaddle/models/expand_v2/input0.x.float32.npy b/ngraph/test/files/paddlepaddle/models/expand_v2/input0.x.float32.npy new file mode 100644 index 0000000000000000000000000000000000000000..495a5f07367c223b9cee61723b7fcc670ac3f628 GIT binary patch literal 152 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= yXCxM+0{I$-ItoB!rm3S)t3V#$+WT6?J~s2Boxl@Kd-tRK_UnrR?H?uD+XDc0Iwg|; literal 0 HcmV?d00001 diff --git a/ngraph/test/files/paddlepaddle/models/expand_v2/output0.npy b/ngraph/test/files/paddlepaddle/models/expand_v2/output0.npy new file mode 100644 index 0000000000000000000000000000000000000000..2d5483540a02093f8c4deb19db05dd6ba2160cea GIT binary patch literal 272 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= zXCxM+0{I$7Its=*3TB!*3bhL40j|BTRqSIkFWLz_(X@9z%5T5EDA4{