Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a2f981a4
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a2f981a4
编写于
12月 09, 2019
作者:
Z
zhupengyang
提交者:
GitHub
12月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] support relu6 (#2582)
test=develop
上级
ea837ec7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
1 deletion
+15
-1
lite/backends/npu/builder.cc
lite/backends/npu/builder.cc
+1
-1
lite/kernels/npu/bridges/act_op.cc
lite/kernels/npu/bridges/act_op.cc
+4
-0
lite/kernels/npu/bridges/act_op_test.cc
lite/kernels/npu/bridges/act_op_test.cc
+9
-0
lite/kernels/npu/bridges/paddle_use_npu_bridges.h
lite/kernels/npu/bridges/paddle_use_npu_bridges.h
+1
-0
未找到文件。
lite/backends/npu/builder.cc
浏览文件 @
a2f981a4
...
...
@@ -148,7 +148,7 @@ int CvtActMode(std::string act_type) {
act_mode
=
1
;
}
else
if
(
act_type
==
"tanh"
)
{
act_mode
=
2
;
}
else
if
(
act_type
==
"relu_clipped"
)
{
}
else
if
(
act_type
==
"relu_clipped"
||
act_type
==
"relu6"
)
{
act_mode
=
3
;
}
else
if
(
act_type
==
"elu"
)
{
act_mode
=
4
;
...
...
lite/kernels/npu/bridges/act_op.cc
浏览文件 @
a2f981a4
...
...
@@ -44,6 +44,9 @@ node_map_type ActConverter(const std::shared_ptr<lite::OpLite> act_op,
if
(
op_type
==
"relu_clipped"
)
{
auto
Relu_clipped_coef
=
op_info
->
GetAttr
<
float
>
(
"Relu_clipped_coef"
);
act_node
->
set_attr_coef
(
Relu_clipped_coef
);
}
else
if
(
op_type
==
"relu6"
)
{
float
Relu_clipped_coef
=
6.
f
;
act_node
->
set_attr_coef
(
Relu_clipped_coef
);
}
else
if
(
op_type
==
"leaky_relu"
)
{
auto
alpha
=
op_info
->
GetAttr
<
float
>
(
"alpha"
);
act_node
->
set_attr_negative_slope
(
alpha
);
...
...
@@ -70,6 +73,7 @@ REGISTER_NPU_BRIDGE(relu, paddle::lite::kernels::npu::bridges::ActConverter);
REGISTER_NPU_BRIDGE
(
tanh
,
paddle
::
lite
::
kernels
::
npu
::
bridges
::
ActConverter
);
REGISTER_NPU_BRIDGE
(
relu_clipped
,
paddle
::
lite
::
kernels
::
npu
::
bridges
::
ActConverter
);
REGISTER_NPU_BRIDGE
(
relu6
,
paddle
::
lite
::
kernels
::
npu
::
bridges
::
ActConverter
);
// REGISTER_NPU_BRIDGE(elu, paddle::lite::kernels::npu::bridges::ActConverter);
REGISTER_NPU_BRIDGE
(
leaky_relu
,
paddle
::
lite
::
kernels
::
npu
::
bridges
::
ActConverter
);
...
...
lite/kernels/npu/bridges/act_op_test.cc
浏览文件 @
a2f981a4
...
...
@@ -55,6 +55,10 @@ void act_ref(const std::shared_ptr<operators::ActivationOp> op) {
for
(
size_t
i
=
0
;
i
<
out
->
numel
();
i
++
)
{
out_data
[
i
]
=
std
::
min
(
std
::
max
(
0.
f
,
x_data
[
i
]),
relu_clipped_coef
);
}
}
else
if
(
op_type
==
"relu6"
)
{
for
(
size_t
i
=
0
;
i
<
out
->
numel
();
i
++
)
{
out_data
[
i
]
=
std
::
min
(
std
::
max
(
0.
f
,
x_data
[
i
]),
6.
f
);
}
}
else
if
(
op_type
==
"leaky_relu"
)
{
auto
alpha
=
op_info
->
GetAttr
<
float
>
(
"alpha"
);
for
(
size_t
i
=
0
;
i
<
out
->
numel
();
i
++
)
{
...
...
@@ -96,6 +100,8 @@ void test_act(std::vector<int64_t> x_shape, std::string op_type) {
opdesc
.
SetInput
(
"X"
,
{
x_var_name
});
opdesc
.
SetOutput
(
"Out"
,
{
out_var_name
});
if
(
op_type
==
"relu_clipped"
)
{
opdesc
.
SetAttr
(
"Relu_clipped_coef"
,
3.
f
);
}
else
if
(
op_type
==
"relu6"
)
{
opdesc
.
SetAttr
(
"Relu_clipped_coef"
,
6.
f
);
}
else
if
(
op_type
==
"leaky_relu"
)
{
opdesc
.
SetAttr
(
"alpha"
,
0.02
f
);
...
...
@@ -125,6 +131,7 @@ TEST(NPUBridges, activation) {
"relu"
,
"tanh"
,
"relu_clipped"
,
"relu6"
,
"leaky_relu"
,
"softsign"
,
"hard_sigmoid"
};
...
...
@@ -149,6 +156,8 @@ USE_LITE_OP(tanh);
USE_NPU_BRIDGE
(
tanh
);
USE_LITE_OP
(
relu_clipped
);
USE_NPU_BRIDGE
(
relu_clipped
);
USE_LITE_OP
(
relu6
);
USE_NPU_BRIDGE
(
relu6
);
USE_LITE_OP
(
leaky_relu
);
USE_NPU_BRIDGE
(
leaky_relu
);
...
...
lite/kernels/npu/bridges/paddle_use_npu_bridges.h
浏览文件 @
a2f981a4
...
...
@@ -20,6 +20,7 @@ USE_NPU_BRIDGE(sigmoid);
USE_NPU_BRIDGE
(
relu
);
USE_NPU_BRIDGE
(
tanh
);
USE_NPU_BRIDGE
(
relu_clipped
);
USE_NPU_BRIDGE
(
relu6
);
USE_NPU_BRIDGE
(
leaky_relu
);
USE_NPU_BRIDGE
(
softsign
);
USE_NPU_BRIDGE
(
hard_sigmoid
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录