Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
48f5f6bd
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
48f5f6bd
编写于
9月 15, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine some operators' python unittests
上级
41271f03
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
57 deletion
+67
-57
python/paddle/v2/framework/tests/test_activation_op.py
python/paddle/v2/framework/tests/test_activation_op.py
+67
-57
未找到文件。
python/paddle/v2/framework/tests/test_activation_op.py
浏览文件 @
48f5f6bd
...
...
@@ -18,21 +18,6 @@ class TestExp(OpTest):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
class
TestRelu
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"relu"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
x
=
np
.
sign
(
x
)
*
np
.
exp
(
np
.
abs
(
x
))
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Y'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
0
)}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
class
TestSigmoid
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"sigmoid"
...
...
@@ -81,8 +66,12 @@ class TestSqrt(OpTest):
class
TestAbs
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"abs"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
x
=
np
.
sign
(
x
)
*
np
.
exp
(
np
.
abs
(
x
))
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
4
,
4
]).
astype
(
"float32"
)
# Because we set delta = 0.005 in caculating numeric gradient,
# if x is too small, such as 0.002, x_neg will be -0.003
# x_pos will be 0.007, so the numeric gradient is unaccurate.
# we should avoid this
x
[
np
.
abs
(
x
)
<
0.005
]
=
0.02
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Y'
:
np
.
abs
(
self
.
inputs
[
'X'
])}
...
...
@@ -93,41 +82,14 @@ class TestAbs(OpTest):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.007
)
class
TestReciprocal
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"reciprocal"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
1
,
2
,
[
11
,
17
]).
astype
(
"float32"
)}
self
.
outputs
=
{
'Y'
:
np
.
reciprocal
(
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.01
)
class
TestLog
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"log"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
}
self
.
outputs
=
{
'Y'
:
np
.
log
(
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
)
class
TestSquare
(
OpTest
):
class
TestRelu
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"square"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
}
self
.
outputs
=
{
'Y'
:
np
.
square
(
self
.
inputs
[
'X'
])}
self
.
op_type
=
"relu"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
# The same reason with TestAbs
x
[
np
.
abs
(
x
)
<
0.005
]
=
0.02
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Y'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
0
)}
def
test_check_output
(
self
):
self
.
check_output
()
...
...
@@ -140,10 +102,13 @@ class TestBRelu(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"brelu"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
4
,
4
]).
astype
(
"float32"
)
x
=
2
*
np
.
sign
(
x
)
*
np
.
exp
(
np
.
abs
(
x
))
self
.
inputs
=
{
'X'
:
x
}
t_min
=
0
t_min
=
1
t_max
=
4
# The same with TestAbs
x
[
np
.
abs
(
x
-
t_min
)
<
0.005
]
=
t_min
+
0.02
x
[
np
.
abs
(
x
-
t_max
)
<
0.005
]
=
t_min
+
0.02
self
.
inputs
=
{
'X'
:
x
}
self
.
attrs
=
{
't_min'
:
t_min
,
't_max'
:
t_max
}
t
=
np
.
copy
(
x
)
t
[
t
<
t_min
]
=
t_min
...
...
@@ -160,10 +125,12 @@ class TestBRelu(OpTest):
class
TestSoftRelu
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"soft_relu"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
4
,
4
]).
astype
(
"float32"
)
x
=
2
*
np
.
sign
(
x
)
*
np
.
exp
(
np
.
abs
(
x
))
x
=
np
.
random
.
uniform
(
-
3
,
3
,
[
4
,
4
]).
astype
(
"float32"
)
threshold
=
2
# The same reason with TestAbs
x
[
np
.
abs
(
x
-
threshold
)
<
0.005
]
=
threshold
+
0.02
x
[
np
.
abs
(
x
+
threshold
)
<
0.005
]
=
-
threshold
+
0.02
self
.
inputs
=
{
'X'
:
x
}
threshold
=
4
self
.
attrs
=
{
'threshold'
:
threshold
}
t
=
np
.
copy
(
x
)
t
[
t
<
-
threshold
]
=
-
threshold
...
...
@@ -177,6 +144,49 @@ class TestSoftRelu(OpTest):
self
.
check_grad
([
'X'
],
'Y'
,
max_relative_error
=
0.02
)
class
TestReciprocal
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"reciprocal"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
1
,
2
,
[
11
,
17
]).
astype
(
"float32"
)}
self
.
outputs
=
{
'Y'
:
np
.
reciprocal
(
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.01
)
class
TestLog
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"log"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
}
self
.
outputs
=
{
'Y'
:
np
.
log
(
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
)
class
TestSquare
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"square"
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
}
self
.
outputs
=
{
'Y'
:
np
.
square
(
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
)
class
TestPow
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"pow"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录