forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from itikhono/itikhono/pdpd/support_mul_outputs
Add support for multiple outputs
- Loading branch information
Showing
8 changed files
with
139 additions
and
16 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
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 @@ | ||
//***************************************************************************** | ||
// 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 "split.h" | ||
#include "utility.hpp" | ||
|
||
namespace ngraph { | ||
namespace frontend { | ||
namespace pdpd { | ||
namespace op { | ||
OutputVector split(const NodeContext& node) { | ||
using namespace ngraph; | ||
using namespace opset6; | ||
const auto& data = node.get_ng_input("X"); | ||
auto dim = node.get_attribute<int32_t>("axis"); | ||
// todo: 'num' can be list of values, in this case we should create VariadicSplit | ||
// todo: support VariadicSplit | ||
auto num_or_sections = node.get_attribute<int32_t>("num"); | ||
auto axis = std::make_shared<Constant>(ngraph::element::i32, Shape{}, dim); | ||
|
||
return std::make_shared<ngraph::opset6::Split>(data, axis, num_or_sections)->outputs(); | ||
} | ||
} // namespace op | ||
} // namespace pdpd | ||
} // namespace frontend | ||
} // namespace ngraph |
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,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. | ||
//***************************************************************************** | ||
|
||
#pragma once | ||
#include "node_context.hpp" | ||
|
||
namespace ngraph { | ||
namespace frontend { | ||
namespace pdpd { | ||
namespace op { | ||
|
||
OutputVector split(const NodeContext& node); | ||
|
||
} // namespace op | ||
} // namespace pdpd | ||
} // namespace frontend | ||
} // namespace ngraph |
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
52 changes: 52 additions & 0 deletions
52
ngraph/test/files/paddlepaddle/gen_scripts/generate_multi_output_split.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,52 @@ | ||
import paddle | ||
from paddle import fluid | ||
import numpy as np | ||
|
||
# it's better to use PYTHON_PATH | ||
# import sys | ||
# sys.path.append('/home/itikhonov/OpenVINO/openvino/bin/intel64/Debug/lib/python_api/python3.6/') | ||
# from openvino.inference_engine import IECore | ||
|
||
|
||
def create_multi_output_model(): | ||
paddle.enable_static() | ||
|
||
# PDPD model creation and inference | ||
num_splits_1 = 10 | ||
inp_blob_1 = np.random.randn(2, num_splits_1, 4, 4).astype(np.float32) | ||
|
||
x = fluid.data(name='x', shape=[2, num_splits_1, 4, 4], dtype='float32') | ||
test_layer = fluid.layers.split(x, num_or_sections=10, dim=1) | ||
|
||
var = [] | ||
for i in range(num_splits_1//2): | ||
add = fluid.layers.elementwise_add(test_layer[2*i], test_layer[2*i+1]) | ||
var.append(add) | ||
|
||
exe = fluid.Executor(fluid.CPUPlace()) | ||
exe.run(fluid.default_startup_program()) | ||
inp_dict = {'x': inp_blob_1} | ||
res_pdpd = exe.run(fluid.default_main_program(), fetch_list=var, feed=inp_dict) | ||
|
||
fluid.io.save_inference_model("../models/multi_output_split", | ||
list(inp_dict.keys()), var, exe, | ||
model_filename="multi_output_split.pdmodel", | ||
params_filename="multi_output_split.pdiparams") | ||
|
||
# IE inference | ||
# ie = IECore() | ||
# path_to_ie_model = "../models/multi_output_split/multi_output_split" | ||
# net = ie.read_network(model=path_to_ie_model + ".xml", weights=path_to_ie_model + ".bin") | ||
# exec_net = ie.load_network(net, "CPU") | ||
# res = exec_net.infer({'x': inp_blob_1}) | ||
# | ||
# # compare results: IE vs PDPD | ||
# idx = 0 | ||
# for key in res: | ||
# comp = np.all(np.isclose(res_pdpd[idx], res[key], rtol=1e-05, atol=1e-08, equal_nan=False)) | ||
# assert comp, "PDPD and IE results are different" | ||
# idx = idx + 1 | ||
|
||
|
||
create_multi_output_model() | ||
|
Binary file added
BIN
+29.4 KB
ngraph/test/files/paddlepaddle/models/multi_output_split/multi_output_split.pdmodel
Binary file not shown.
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