-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 grid_sampler op #15869
Merged
ceciliapeng2011
merged 21 commits into
openvinotoolkit:master
from
Patrick-Star125:grid
May 12, 2023
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ce3cc16
update op linspace
Patrick-Star125 f54ca35
Merge branch 'master' of https://github.com/Patrick-Star125/openvino
Patrick-Star125 284b373
Merge branch 'openvinotoolkit:master' into master
Patrick-Star125 f375c6d
rewrite function name
Patrick-Star125 23598e4
Merge branch 'master' of https://github.com/Patrick-Star125/openvino
Patrick-Star125 f3c78a6
add paddle grid_sample op mapping
Patrick-Star125 25c7d9d
add op_fuzzy
Patrick-Star125 86617cd
adjust op logic
Patrick-Star125 5946453
adjust op name
Patrick-Star125 963b880
Merge branch 'master' into grid
Patrick-Star125 95aa807
Merge branch 'master' into grid
Patrick-Star125 1ecd14c
Merge branch 'master' into grid
Patrick-Star125 703420e
format code
Patrick-Star125 20de881
Merge branch 'grid' of https://github.com/Patrick-Star125/openvino in…
Patrick-Star125 7eeb4fc
add tests
Patrick-Star125 228fcab
adjust test
Patrick-Star125 7f227c4
adjust test
Patrick-Star125 28702ce
adjust test
Patrick-Star125 5b6f7a4
adjust test
Patrick-Star125 1953e1b
format code
Patrick-Star125 e4db1c6
Merge branch 'master' into grid
xczhai 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,29 @@ | ||
// 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 grid_sampler(const NodeContext& node) { | ||
auto data = node.get_input("X"); | ||
auto grid = node.get_input("Grid"); | ||
default_opset::GridSample::Attributes attributes{}; | ||
|
||
attributes.align_corners = node.get_attribute<bool>("align_corners", 1); | ||
attributes.mode = ov::EnumNames<default_opset::GridSample::InterpolationMode>::as_enum( | ||
node.get_attribute<std::string>("mode", "bilinear")); | ||
attributes.padding_mode = ov::EnumNames<default_opset::GridSample::PaddingMode>::as_enum( | ||
node.get_attribute<std::string>("padding_mode", "zeros")); | ||
|
||
return node.default_single_output_mapping({std::make_shared<default_opset::GridSample>(data, grid, attributes)}, | ||
{"Output"}); | ||
} | ||
} // 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
59 changes: 59 additions & 0 deletions
59
src/frontends/paddle/tests/test_models/gen_scripts/generate_grid_sampler.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,59 @@ | ||
# Copyright (C) 2018-2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# grid_sampler paddle model generator | ||
# | ||
import paddle | ||
import numpy as np | ||
from save_model import saveModel | ||
import sys | ||
|
||
|
||
def grid_sampler(name: str, x, grid, mode="bilinear", padding_mode="zeros", align_corners=True, not_empty=True, | ||
is_dynamic=False): | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
if is_dynamic: | ||
x_node = paddle.static.data(name="x", shape=(-1, -1, -1, -1), dtype=x.dtype) | ||
grid_node = paddle.static.data(name="grid", shape=(-1, -1, -1, 2), dtype=grid.dtype) | ||
else: | ||
x_node = paddle.static.data(name="x", shape=x.shape, dtype=x.dtype) | ||
grid_node = paddle.static.data(name="grid", shape=grid.shape, dtype=grid.dtype) | ||
out = paddle.nn.functional.grid_sample(x_node, grid_node, mode=mode, padding_mode=padding_mode, | ||
align_corners=align_corners) if not_empty else paddle.nn.functional.grid_sample( | ||
x_node, grid_node) | ||
place = paddle.CPUPlace() | ||
exe = paddle.static.Executor(place) | ||
exe.run(paddle.static.default_startup_program()) | ||
outs = exe.run(feed={"x": x, "grid": grid}, fetch_list=[out]) | ||
saveModel(name, exe, feedkeys=['x', 'grid'], fetchlist=[out], inputs=[x, grid], outputs=[outs[0]], | ||
target_dir=sys.argv[1]) | ||
|
||
return outs[0] | ||
|
||
|
||
def main(): | ||
dtype = np.float32 | ||
x = np.random.randn(2, 2, 3, 3).astype(dtype) | ||
grid = np.random.uniform(-1, 1, [2, 3, 3, 2]).astype(dtype) | ||
grid_sampler(name='grid_sampler_1', x=x, grid=grid, not_empty=False) | ||
|
||
x = np.random.randn(2, 3, 5, 6).astype(dtype) | ||
grid = np.random.uniform(-1, 1, [2, 8, 9, 2]).astype(dtype) | ||
mode = "nearest" | ||
padding_mode = "reflection" | ||
align_corners = False | ||
grid_sampler(name='grid_sampler_2', x=x, grid=grid, mode=mode, padding_mode=padding_mode, | ||
align_corners=align_corners) | ||
|
||
x = np.random.randn(2, 3, 128, 128).astype(dtype) | ||
grid = np.random.uniform(-1, 1, [2, 130, 130, 2]).astype(dtype) | ||
padding_mode = "border" | ||
grid_sampler(name='grid_sampler_dyn', x=x, grid=grid, mode=mode, padding_mode=padding_mode, | ||
align_corners=align_corners, is_dynamic=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.
please correct the code format here as log reports.
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.
Done