Skip to content

Commit

Permalink
Merge pull request #5 from mangguo321/mang/merge_to_yi_branch
Browse files Browse the repository at this point in the history
Mang/merge to yi branch
  • Loading branch information
zhangYiIntel authored Apr 23, 2021
2 parents 03d93cb + 74b24d9 commit 49d4ff2
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inference-engine/thirdparty/mkl-dnn
10 changes: 9 additions & 1 deletion ngraph/frontend/paddlepaddle/src/op/scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ namespace op {
NamedOutputs scale (const NodeContext& node) {
auto data = node.get_ng_input("X");
auto scale = ngraph::opset6::Constant::create(ngraph::element::f32, {1}, {node.get_attribute<float>("scale")});
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Multiply>(data, scale)}, {"Out"});
auto bias = ngraph::opset6::Constant::create(ngraph::element::f32, {1}, {node.get_attribute<float>("bias")});
auto bias_after_scale = node.get_attribute<bool>("bias_after_scale");
if(!bias_after_scale) {
auto node_add = std::make_shared<ngraph::opset6::Add>(data, bias);
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Multiply>(node_add, scale)}, {"Out"});
} else {
auto node_multiply = std::make_shared<ngraph::opset6::Multiply>(data, scale);
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Add>(node_multiply, bias)}, {"Out"});
}
}

}}}}
43 changes: 43 additions & 0 deletions ngraph/test/files/paddlepaddle/gen_scripts/generate_reshape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# reshape paddle model generator
#
import numpy as np
from save_model import saveModel

data_type = 'float32'

def reshape(name : str, x, out_shape):
import paddle as pdpd
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.reshape(x=node_x, shape=out_shape)

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():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
]]], dtype=np.float32)
out_shape = [1, 1, 2, 8]
reshape("reshape", data, out_shape)



if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions ngraph/test/files/paddlepaddle/gen_scripts/generate_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel

data_type = 'float32'

def pdpd_scale(name : str, x, scale, bias, attrs : dict):
import paddle as pdpd
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='float32')
out = pdpd.scale(x=node_x, scale=scale, bias=bias,
bias_after_scale=attrs['bias_after_scale'])

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():
scale = 2.0
bias = 1.0
data = np.random.random([2, 3]).astype("float32")
pdpd_attrs = {
'bias_after_scale' : True,
}
pdpd_scale("scale_test1", data, scale, bias, pdpd_attrs)

pdpd_attrs = {
'bias_after_scale' : False,
}
pdpd_scale("scale_test2", data, scale, bias, pdpd_attrs)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions ngraph/test/files/paddlepaddle/models/models.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ maxPool_test5,
#maxPool_test6,
avgAdaptivePool2D_test1,
#maxAdaptivePool2D_test1,
scale_test1,
scale_test2,
reshape,

0 comments on commit 49d4ff2

Please sign in to comment.