Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
0c3eee09
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0c3eee09
编写于
9月 28, 2017
作者:
A
Abhinav Arora
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implementing the SoftSign activation operator
上级
184768e0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
0 deletion
+64
-0
paddle/operators/activation_op.cc
paddle/operators/activation_op.cc
+20
-0
paddle/operators/activation_op.cu
paddle/operators/activation_op.cu
+7
-0
paddle/operators/activation_op.h
paddle/operators/activation_op.h
+20
-0
python/paddle/v2/framework/tests/test_activation_op.py
python/paddle/v2/framework/tests/test_activation_op.py
+17
-0
未找到文件。
paddle/operators/activation_op.cc
浏览文件 @
0c3eee09
...
@@ -132,6 +132,17 @@ class SquareOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -132,6 +132,17 @@ class SquareOpMaker : public framework::OpProtoAndCheckerMaker {
}
}
};
};
class
SoftsignOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
SoftsignOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"Input of Softsign operator"
);
AddOutput
(
"Y"
,
"Output of Softsign operator"
);
AddComment
(
"Softsign activation operator, softsign(x) = x / (1 + |x|)"
);
}
};
template
<
typename
AttrType
>
template
<
typename
AttrType
>
class
BReluOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
class
BReluOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
public:
...
@@ -277,6 +288,15 @@ REGISTER_OP_CPU_KERNEL(
...
@@ -277,6 +288,15 @@ REGISTER_OP_CPU_KERNEL(
square_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
square_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
ops
::
SquareGradFunctor
<
float
>>
);
ops
::
SquareGradFunctor
<
float
>>
);
REGISTER_OP
(
softsign
,
ops
::
ActivationOp
,
ops
::
SoftsignOpMaker
,
softsign_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP_CPU_KERNEL
(
softsign
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
ops
::
SoftsignFunctor
<
float
>>
);
REGISTER_OP_CPU_KERNEL
(
softsign_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
ops
::
SoftsignGradFunctor
<
float
>>
);
REGISTER_OP
(
brelu
,
ops
::
ActivationOp
,
ops
::
BReluOpMaker
<
float
>
,
brelu_grad
,
REGISTER_OP
(
brelu
,
ops
::
ActivationOp
,
ops
::
BReluOpMaker
<
float
>
,
brelu_grad
,
ops
::
ActivationOpGrad
);
ops
::
ActivationOpGrad
);
REGISTER_OP_CPU_KERNEL
(
brelu
,
REGISTER_OP_CPU_KERNEL
(
brelu
,
...
...
paddle/operators/activation_op.cu
浏览文件 @
0c3eee09
...
@@ -80,6 +80,13 @@ REGISTER_OP_GPU_KERNEL(
...
@@ -80,6 +80,13 @@ REGISTER_OP_GPU_KERNEL(
square_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
square_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
ops
::
SquareGradFunctor
<
float
>>
);
ops
::
SquareGradFunctor
<
float
>>
);
REGISTER_OP_GPU_KERNEL
(
softsign
,
ops
::
ActivationKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
ops
::
SoftsignFunctor
<
float
>>
);
REGISTER_OP_GPU_KERNEL
(
softsign_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
ops
::
SoftsignGradFunctor
<
float
>>
);
REGISTER_OP_GPU_KERNEL
(
brelu
,
REGISTER_OP_GPU_KERNEL
(
brelu
,
ops
::
BReluKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
BReluKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
brelu_grad
,
REGISTER_OP_GPU_KERNEL
(
brelu_grad
,
...
...
paddle/operators/activation_op.h
浏览文件 @
0c3eee09
...
@@ -201,6 +201,26 @@ struct SquareGradFunctor {
...
@@ -201,6 +201,26 @@ struct SquareGradFunctor {
}
}
};
};
// softsign(x) = x / (1 + |x|)
template
<
typename
T
>
struct
SoftsignFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
y
.
device
(
d
)
=
x
/
(
static_cast
<
T
>
(
1
)
+
x
.
abs
());
}
};
// d(softsign(x))/dx = 1 / (1 + |x|)^2
// Taken from https://en.wikipedia.org/wiki/Activation_function
template
<
typename
T
>
struct
SoftsignGradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
dx
.
device
(
d
)
=
dy
*
(
static_cast
<
T
>
(
1
)
/
(
static_cast
<
T
>
(
1
)
+
x
.
abs
()).
square
());
}
};
template
<
typename
Place
,
typename
T
,
typename
AttrType
=
T
>
template
<
typename
Place
,
typename
T
,
typename
AttrType
=
T
>
class
BReluKernel
:
public
framework
::
OpKernel
<
T
>
{
class
BReluKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
...
...
python/paddle/v2/framework/tests/test_activation_op.py
浏览文件 @
0c3eee09
...
@@ -219,5 +219,22 @@ class TestSTanh(OpTest):
...
@@ -219,5 +219,22 @@ class TestSTanh(OpTest):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
class
TestSoftsign
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"softsign"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
}
self
.
outputs
=
{
'Y'
:
np
.
divide
(
self
.
inputs
[
'X'
],
1
+
np
.
abs
(
self
.
inputs
[
'X'
]))
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录