forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'yi3/update_to_latest' into new_API
- Loading branch information
Showing
11 changed files
with
340 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
ngraph/frontend/paddlepaddle/src/op/fill_constant_batch_size_like.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//***************************************************************************** | ||
// 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 <ngraph/opsets/opset6.hpp> | ||
#include "fill_constant_batch_size_like.hpp" | ||
#include <paddlepaddle_frontend/utility.hpp> | ||
|
||
namespace ngraph { | ||
namespace frontend { | ||
namespace pdpd { | ||
namespace op { | ||
|
||
NamedOutputs fill_constant_batch_size_like (const NodeContext& node) { | ||
auto input_dim_idx = node.get_attribute<int32_t>("input_dim_idx"); | ||
auto output_dim_idx = node.get_attribute<int32_t>("output_dim_idx"); | ||
auto value = node.get_attribute<float>("value"); | ||
auto shapes = node.get_attribute<std::vector<int32_t> >("shape"); | ||
auto input = node.get_ng_input("Input"); | ||
auto parial_shape = input.get_partial_shape(); | ||
PDPD_ASSERT(parial_shape.is_static(), "fill_constant_batch_size_like: must use static shape."); | ||
auto static_shape = parial_shape.get_shape(); | ||
PDPD_ASSERT(input_dim_idx < (int32_t)static_shape.size(), "fill_constant_batch_size_like: input_dim_idx should not exceed input dims."); | ||
PDPD_ASSERT(output_dim_idx < (int32_t)shapes.size(), "fill_constant_batch_size_like: output_dim_idx should not exceed shapes dims."); | ||
shapes[output_dim_idx] = static_shape[input_dim_idx]; | ||
return node.default_single_output_mapping( | ||
{std::make_shared<ngraph::opset6::Constant>(ngraph::element::f32, Shape(shapes.begin(), shapes.end()), value)}, | ||
{"Out"}); | ||
} | ||
|
||
}}}} |
27 changes: 27 additions & 0 deletions
27
ngraph/frontend/paddlepaddle/src/op/fill_constant_batch_size_like.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 fill_constant_batch_size_like (const NodeContext& node); | ||
|
||
}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//***************************************************************************** | ||
// 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 <ngraph/opsets/opset6.hpp> | ||
#include "greater_equal.hpp" | ||
#include <paddlepaddle_frontend/utility.hpp> | ||
|
||
namespace ngraph { | ||
namespace frontend { | ||
namespace pdpd { | ||
namespace op { | ||
|
||
NamedOutputs greater_equal (const NodeContext& node) { | ||
auto x = node.get_ng_input("X"); | ||
auto y = node.get_ng_input("Y"); | ||
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::GreaterEqual>(x, y)}, {"Out"}); | ||
} | ||
|
||
}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 greater_equal (const NodeContext& node); | ||
|
||
}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//***************************************************************************** | ||
// 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 <ngraph/opsets/opset6.hpp> | ||
#include "log.hpp" | ||
#include <paddlepaddle_frontend/utility.hpp> | ||
|
||
namespace ngraph { | ||
namespace frontend { | ||
namespace pdpd { | ||
namespace op { | ||
|
||
NamedOutputs log (const NodeContext& node) { | ||
auto x = node.get_ng_input("X"); | ||
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Log>(x)}, {"Out"}); | ||
} | ||
|
||
}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 log (const NodeContext& node); | ||
|
||
}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
ngraph/test/files/paddlepaddle/gen_scripts/generate_fill_constant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# fill_const paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle as pdpd | ||
|
||
data_type = 'float32' | ||
|
||
def fill_constant(name : str, shape : list, dtype, value): | ||
pdpd.enable_static() | ||
|
||
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): | ||
out = pdpd.fluid.layers.fill_constant(shape=shape, value=value, dtype=dtype, name='fill_constant') | ||
|
||
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( | ||
fetch_list=[out]) | ||
|
||
saveModel(name, exe, feedkeys=[], fetchlist=[out], inputs=[], outputs=[outs[0]]) | ||
|
||
return outs[0] | ||
|
||
def main(): | ||
fill_constant("fill_constant", [2, 3, 4], data_type, 0.03) | ||
|
||
if __name__ == "__main__": | ||
main() |
38 changes: 38 additions & 0 deletions
38
ngraph/test/files/paddlepaddle/gen_scripts/generate_fill_constant_batch_size_like.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# fill_constant_batch_size_like paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle as pdpd | ||
|
||
data_type = 'float32' | ||
|
||
def fill_constant_batch_size_like(name : str, x, shape, dtype, value, input_dim_idx=0, output_dim_idx=0): | ||
pdpd.enable_static() | ||
|
||
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): | ||
like = pdpd.static.data(name='x', shape=x.shape, dtype = data_type) | ||
out = pdpd.fluid.layers.fill_constant_batch_size_like(input=like, shape=shape, \ | ||
value=value, dtype=dtype, \ | ||
output_dim_idx=output_dim_idx, input_dim_idx=input_dim_idx) | ||
|
||
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(): | ||
x = np.random.rand(4, 3, 2).astype(data_type) | ||
fill_constant_batch_size_like("fill_constant_batch_size_like", \ | ||
x, [1, -1, 3], data_type, 0.03, 2, 1) | ||
|
||
if __name__ == "__main__": | ||
main() |
40 changes: 40 additions & 0 deletions
40
ngraph/test/files/paddlepaddle/gen_scripts/generate_greater_equal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# greater_equal paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle as pdpd | ||
|
||
data_type = 'float32' | ||
|
||
def greater_equal(name : str, x, y): | ||
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) | ||
node_y = pdpd.static.data(name='y', shape=y.shape, dtype = data_type) | ||
out = pdpd.fluid.layers.greater_equal(x=node_x, y=node_y, name='greater_equal') | ||
# save model does not support boolean type | ||
out = pdpd.cast(out, data_type) | ||
|
||
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, 'y' : y}, | ||
fetch_list=[out]) | ||
|
||
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]]) | ||
|
||
return outs[0] | ||
|
||
def main(): | ||
x = np.array([0, 1, 2, 3]).astype(data_type) | ||
y = np.array([1, 0, 2, 4]).astype(data_type) | ||
|
||
greater_equal("greater_equal", x, y) | ||
|
||
if __name__ == "__main__": | ||
main() |
36 changes: 36 additions & 0 deletions
36
ngraph/test/files/paddlepaddle/gen_scripts/generate_log.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# log paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle as pdpd | ||
|
||
data_type = 'float32' | ||
|
||
def log(name : str, x): | ||
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.fluid.layers.log(node_x, name = 'log') | ||
|
||
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(): | ||
x = np.array([0, 1, 2, -10]).astype(data_type) | ||
|
||
log("log", x) | ||
|
||
if __name__ == "__main__": | ||
main() |