-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【PaddlePaddle Hackathon 4】add paddle flip op #15828
Merged
ceciliapeng2011
merged 18 commits into
openvinotoolkit:master
from
Asthestarsfalll:flip
May 19, 2023
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3febe47
add flip op
Asthestarsfalll 4554226
Merge branch 'openvinotoolkit:master' into flip
Asthestarsfalll 0e171a7
fix
Asthestarsfalll bfbf42e
Merge branch 'openvinotoolkit:master' into flip
Asthestarsfalll cfc5d42
fix signedness error
Asthestarsfalll 4987fab
update flip
Asthestarsfalll f36f825
Merge branch 'master' into flip
Asthestarsfalll 89165f6
Merge branch 'master' into flip
Asthestarsfalll 501481c
use Slice
Asthestarsfalll 2f3e5c8
remove redundant codes
Asthestarsfalll 138949d
Merge branch 'master' into flip
Asthestarsfalll e7db770
Merge branch 'master' into flip
Asthestarsfalll ffa0e71
Merge branch 'master' into flip
Asthestarsfalll 5a23e13
Merge branch 'master' into flip
Asthestarsfalll d549f63
unify flip and reverse
Asthestarsfalll 73e8c56
Merge branch 'master' into flip
ceciliapeng2011 a975600
fix bug
Asthestarsfalll b066b04
Merge branch 'master' into flip
Asthestarsfalll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,17 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "reverse_op.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs flip(const NodeContext& node) { | ||
return reverse_op(node); | ||
} | ||
} // namespace op | ||
} // namespace paddle | ||
} // namespace frontend | ||
} // namespace ov |
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
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,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<std::vector<int32_t>>("axis"); | ||
auto axes_length = axes.size(); | ||
const auto starts = | ||
default_opset::Constant::create(element::i32, | ||
{axes_length}, | ||
std::vector<int32_t>(axes_length, std::numeric_limits<int32_t>::max())); | ||
const auto stops = | ||
default_opset::Constant::create(element::i32, | ||
{axes_length}, | ||
std::vector<int32_t>(axes_length, std::numeric_limits<int32_t>::min())); | ||
const auto steps = | ||
default_opset::Constant::create(element::i32, {axes_length}, std::vector<int32_t>(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<default_opset::Slice>(data_node, starts, stops, steps, axes_node)}, | ||
{"Out"}); | ||
} | ||
} // namespace op | ||
} // namespace paddle | ||
} // namespace frontend | ||
} // namespace ov |
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
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
73 changes: 73 additions & 0 deletions
73
src/frontends/paddle/tests/test_models/gen_scripts/generate_flip.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,73 @@ | ||
# | ||
# flip paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle | ||
import sys | ||
|
||
|
||
def flip(name: str, x, axis, is_dynamic=False): | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
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) | ||
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] | ||
# axis = [3, 1] | ||
x = np.random.randn(3, 2, 1, 5).astype(data_type) | ||
flip("flip_2", x, axis) | ||
|
||
data_type = 'float32' | ||
axis = [0, 1] | ||
x = np.random.randn(1, 1, 1, 1).astype(data_type) | ||
flip("flip_3", x, axis) | ||
|
||
data_type = 'int64' | ||
axis = 1 | ||
x = np.random.randint(-1, 3, (5, 3, 1, 1)).astype(data_type) | ||
flip("flip_4", x, axis) | ||
|
||
data_type = 'float32' | ||
axis = -1 | ||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can have "bool" type tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested bool type before, but it occurs error that openvino test do not support bool output