diff --git a/ngraph/frontend/paddlepaddle/src/op/shape.cpp b/ngraph/frontend/paddlepaddle/src/op/shape.cpp new file mode 100644 index 00000000000000..8d5f21ef7929f6 --- /dev/null +++ b/ngraph/frontend/paddlepaddle/src/op/shape.cpp @@ -0,0 +1,30 @@ +//***************************************************************************** +// 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 "shape.hpp" + +namespace ngraph { +namespace frontend { +namespace pdpd { +namespace op { + +NamedOutputs shape (const NodeContext& node) { + auto data = node.get_ng_input("Input"); + return node.default_single_output_mapping({std::make_shared(data)}, {"Out"}); +} + +}}}} \ No newline at end of file diff --git a/ngraph/frontend/paddlepaddle/src/op/shape.hpp b/ngraph/frontend/paddlepaddle/src/op/shape.hpp new file mode 100644 index 00000000000000..79627f44e66c35 --- /dev/null +++ b/ngraph/frontend/paddlepaddle/src/op/shape.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 shape (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 31bcbe8488186f..ea2cd49c2f655c 100644 --- a/ngraph/frontend/paddlepaddle/src/op_table.cpp +++ b/ngraph/frontend/paddlepaddle/src/op_table.cpp @@ -53,6 +53,7 @@ #include "op/greater_equal.hpp" #include "op/log.hpp" #include "op/fill_constant_batch_size_like.hpp" +#include "op/shape.hpp" #include "op_table.hpp" @@ -111,7 +112,8 @@ std::map get_supported_ops() { {"greater_equal", op::greater_equal}, {"log", op::log}, {"fill_constant_batch_size_like", op::fill_constant_batch_size_like}, - {"sync_batch_norm", op::batch_norm} + {"sync_batch_norm", op::batch_norm}, + {"shape", op::shape} }; }; diff --git a/ngraph/test/files/paddlepaddle/gen_scripts/generate_shape.py b/ngraph/test/files/paddlepaddle/gen_scripts/generate_shape.py new file mode 100644 index 00000000000000..3333d75d15acf9 --- /dev/null +++ b/ngraph/test/files/paddlepaddle/gen_scripts/generate_shape.py @@ -0,0 +1,37 @@ +# +# pool2d paddle model generator +# +import numpy as np +from save_model import saveModel + +data_type = 'float32' + +def pdpd_shape(name : str, x): + import paddle as pdpd + 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='float32') + out = pdpd.shape(node_x) + out = pdpd.cast(out, np.float32) + 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(): + p=0.5 + data = np.random.random(size=(2,3)).astype('float32') + pdpd_shape("shape", data) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ngraph/test/files/paddlepaddle/models/models.csv b/ngraph/test/files/paddlepaddle/models/models.csv index 1b392b554e10c4..6f544d50d7b55c 100644 --- a/ngraph/test/files/paddlepaddle/models/models.csv +++ b/ngraph/test/files/paddlepaddle/models/models.csv @@ -68,3 +68,4 @@ squeeze_null_axes, transpose2, unsqueeze, yolo_box_test1, +shape, diff --git a/ngraph/test/files/paddlepaddle/models/shape/__model__ b/ngraph/test/files/paddlepaddle/models/shape/__model__ new file mode 100644 index 00000000000000..4ec8cc23d40dab Binary files /dev/null and b/ngraph/test/files/paddlepaddle/models/shape/__model__ differ diff --git a/ngraph/test/files/paddlepaddle/models/shape/input0.npy b/ngraph/test/files/paddlepaddle/models/shape/input0.npy new file mode 100644 index 00000000000000..70114397764f6d Binary files /dev/null and b/ngraph/test/files/paddlepaddle/models/shape/input0.npy differ diff --git a/ngraph/test/files/paddlepaddle/models/shape/input0.x.float32.npy b/ngraph/test/files/paddlepaddle/models/shape/input0.x.float32.npy new file mode 100644 index 00000000000000..70114397764f6d Binary files /dev/null and b/ngraph/test/files/paddlepaddle/models/shape/input0.x.float32.npy differ diff --git a/ngraph/test/files/paddlepaddle/models/shape/output0.npy b/ngraph/test/files/paddlepaddle/models/shape/output0.npy new file mode 100644 index 00000000000000..0c34f578ad5070 Binary files /dev/null and b/ngraph/test/files/paddlepaddle/models/shape/output0.npy differ diff --git a/ngraph/test/files/paddlepaddle/models/shape/shape.pdmodel b/ngraph/test/files/paddlepaddle/models/shape/shape.pdmodel new file mode 100644 index 00000000000000..be20fd8ce8879c Binary files /dev/null and b/ngraph/test/files/paddlepaddle/models/shape/shape.pdmodel differ