-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
128 additions
and
23 deletions.
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
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,34 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "default_opset.hpp" | ||
#include "openvino/frontend/paddle/node_context.hpp" | ||
#include "openvino/opsets/opset1.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
namespace { | ||
NamedOutputs reverse_op(const NodeContext& node) { | ||
auto x = node.get_input("X"); | ||
// axis is a vector | ||
auto axis = node.get_attribute<std::vector<int32_t>>("axis"); | ||
// try to keep the axis positive since reverse IR doesn't support negative axis. | ||
const auto dims = static_cast<int32_t>(x.get_partial_shape().rank().get_length()); | ||
std::for_each(axis.begin(), axis.end(), [&dims](int32_t& value) { | ||
if (value < 0) { | ||
value += dims; | ||
} | ||
}); | ||
|
||
auto axis_node = std::make_shared<default_opset::Constant>(ngraph::element::i32, Shape{axis.size()}, axis); | ||
auto reverse_node = std::make_shared<ov::opset1::Reverse>(x, axis_node, ov::opset1::Reverse::Mode::INDEX); | ||
return node.default_single_output_mapping({reverse_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
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
61 changes: 61 additions & 0 deletions
61
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,61 @@ | ||
# Copyright (C) 2018-2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# flip paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import sys | ||
import paddle | ||
|
||
def flip(name: str, x, axis, use_static=True, dtype="float32"): | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
if use_static: | ||
node_x = paddle.static.data(name='x', shape=x.shape, dtype=dtype) | ||
else: | ||
node_x = paddle.fluid.data(name='x', shape=[1, 1, -1, -1], dtype=dtype) | ||
out = paddle.flip(node_x, 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(): | ||
data1 = np.array([0,1,2], dtype='int32') | ||
flip("flip_static_1", data1, 0, True, 'int32') | ||
|
||
data2 = np.array([[0,1,2], [3,4,5], [6,7,8]], dtype='float32') | ||
flip("flip_static_2", data2, 1, True, 'float32') | ||
|
||
data3 = np.array([[0,1,2], [3,4,5], [6,7,8]], dtype='float32') | ||
flip("flip_static_3", data3, [0, 1], True, 'float32') | ||
|
||
data4 = np.array([[0,1,2], [3,4,5], [6,7,8]], dtype='int32') | ||
flip("flip_static_4", data4, -1, True, 'int32') | ||
|
||
data5 = np.random.randn(1, 1, 32, 32).astype('int32') | ||
flip("flip_dynamic_1", data5, [2], False, dtype='int32') | ||
|
||
data6 = np.random.randn(1, 1, 64, 64).astype('float32') | ||
flip("flip_dynamic_2", data6, [3], False, dtype='float32') | ||
|
||
data7 = np.random.randn(1, 1, 112, 112).astype('float32') | ||
flip("flip_dynamic_3", data7, [2,3], False, dtype='float32') | ||
|
||
data8 = np.random.randn(1, 1, 224, 224).astype('int32') | ||
flip("flip_dynamic_4", data8, [-2, -1], False, dtype='int32') | ||
|
||
if __name__ == "__main__": | ||
main() |
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