Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
78a4273e
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
78a4273e
编写于
9月 27, 2020
作者:
S
Shang Zhizhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add paddle.enable_static() to some testcase
上级
a85592bc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
0 deletion
+36
-0
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+36
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
78a4273e
...
@@ -140,6 +140,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
...
@@ -140,6 +140,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
out1
=
F
.
log_sigmoid
(
x
)
out1
=
F
.
log_sigmoid
(
x
)
...
@@ -163,6 +164,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
...
@@ -163,6 +164,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
out
=
paddle
.
fluid
.
layers
.
logsigmoid
(
x
)
out
=
paddle
.
fluid
.
layers
.
logsigmoid
(
x
)
...
@@ -172,6 +174,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
...
@@ -172,6 +174,7 @@ class TestLogSigmoidAPI(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_ref
,
res
[
0
]))
self
.
assertTrue
(
np
.
allclose
(
out_ref
,
res
[
0
]))
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
log_sigmoid
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
log_sigmoid
,
1
)
...
@@ -215,6 +218,7 @@ class TestTanhAPI(unittest.TestCase):
...
@@ -215,6 +218,7 @@ class TestTanhAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
],
self
.
dtype
)
x
=
paddle
.
data
(
'X'
,
[
10
,
12
],
self
.
dtype
)
out1
=
F
.
tanh
(
x
)
out1
=
F
.
tanh
(
x
)
...
@@ -239,6 +243,7 @@ class TestTanhAPI(unittest.TestCase):
...
@@ -239,6 +243,7 @@ class TestTanhAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
[
10
,
12
],
self
.
dtype
)
x
=
fluid
.
data
(
'X'
,
[
10
,
12
],
self
.
dtype
)
out
=
fluid
.
layers
.
tanh
(
x
)
out
=
fluid
.
layers
.
tanh
(
x
)
...
@@ -248,6 +253,7 @@ class TestTanhAPI(unittest.TestCase):
...
@@ -248,6 +253,7 @@ class TestTanhAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
tanh
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
tanh
,
1
)
...
@@ -473,6 +479,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
...
@@ -473,6 +479,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out1
=
F
.
tanhshrink
(
x
)
out1
=
F
.
tanhshrink
(
x
)
...
@@ -496,6 +503,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
...
@@ -496,6 +503,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out
=
fluid
.
layers
.
tanh_shrink
(
x
)
out
=
fluid
.
layers
.
tanh_shrink
(
x
)
...
@@ -505,6 +513,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
...
@@ -505,6 +513,7 @@ class TestTanhshrinkAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
tanhshrink
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
tanhshrink
,
1
)
...
@@ -560,6 +569,7 @@ class TestHardShrinkAPI(unittest.TestCase):
...
@@ -560,6 +569,7 @@ class TestHardShrinkAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
out1
=
F
.
hardshrink
(
x
)
out1
=
F
.
hardshrink
(
x
)
...
@@ -590,6 +600,7 @@ class TestHardShrinkAPI(unittest.TestCase):
...
@@ -590,6 +600,7 @@ class TestHardShrinkAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
[
10
,
12
])
x
=
fluid
.
data
(
'X'
,
[
10
,
12
])
out
=
fluid
.
layers
.
hard_shrink
(
x
)
out
=
fluid
.
layers
.
hard_shrink
(
x
)
...
@@ -599,6 +610,7 @@ class TestHardShrinkAPI(unittest.TestCase):
...
@@ -599,6 +610,7 @@ class TestHardShrinkAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
hardshrink
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
hardshrink
,
1
)
...
@@ -626,6 +638,7 @@ class TestHardtanhAPI(unittest.TestCase):
...
@@ -626,6 +638,7 @@ class TestHardtanhAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
out1
=
F
.
hardtanh
(
x
)
out1
=
F
.
hardtanh
(
x
)
...
@@ -656,6 +669,7 @@ class TestHardtanhAPI(unittest.TestCase):
...
@@ -656,6 +669,7 @@ class TestHardtanhAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
hardtanh
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
hardtanh
,
1
)
...
@@ -703,6 +717,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
...
@@ -703,6 +717,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out1
=
F
.
softshrink
(
x
,
self
.
threshold
)
out1
=
F
.
softshrink
(
x
,
self
.
threshold
)
...
@@ -726,6 +741,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
...
@@ -726,6 +741,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out
=
fluid
.
layers
.
softshrink
(
x
,
self
.
threshold
)
out
=
fluid
.
layers
.
softshrink
(
x
,
self
.
threshold
)
...
@@ -735,6 +751,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
...
@@ -735,6 +751,7 @@ class TestSoftshrinkAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
softshrink
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
softshrink
,
1
)
...
@@ -960,6 +977,7 @@ class TestReluAPI(unittest.TestCase):
...
@@ -960,6 +977,7 @@ class TestReluAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
out1
=
F
.
relu
(
x
)
out1
=
F
.
relu
(
x
)
...
@@ -983,6 +1001,7 @@ class TestReluAPI(unittest.TestCase):
...
@@ -983,6 +1001,7 @@ class TestReluAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
relu
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
relu
,
1
)
...
@@ -1050,6 +1069,7 @@ class TestLeakyReluAPI(unittest.TestCase):
...
@@ -1050,6 +1069,7 @@ class TestLeakyReluAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
out1
=
F
.
leaky_relu
(
x
)
out1
=
F
.
leaky_relu
(
x
)
...
@@ -1080,6 +1100,7 @@ class TestLeakyReluAPI(unittest.TestCase):
...
@@ -1080,6 +1100,7 @@ class TestLeakyReluAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
[
10
,
12
])
x
=
fluid
.
data
(
'X'
,
[
10
,
12
])
out
=
fluid
.
layers
.
leaky_relu
(
x
,
0.01
)
out
=
fluid
.
layers
.
leaky_relu
(
x
,
0.01
)
...
@@ -1089,6 +1110,7 @@ class TestLeakyReluAPI(unittest.TestCase):
...
@@ -1089,6 +1110,7 @@ class TestLeakyReluAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
leaky_relu
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
leaky_relu
,
1
)
...
@@ -1155,6 +1177,7 @@ class TestGELUAPI(unittest.TestCase):
...
@@ -1155,6 +1177,7 @@ class TestGELUAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
x
=
paddle
.
data
(
'X'
,
[
11
,
17
])
out1
=
F
.
gelu
(
x
)
out1
=
F
.
gelu
(
x
)
...
@@ -1185,6 +1208,7 @@ class TestGELUAPI(unittest.TestCase):
...
@@ -1185,6 +1208,7 @@ class TestGELUAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
gelu
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
gelu
,
1
)
...
@@ -1273,6 +1297,7 @@ class TestRelu6API(unittest.TestCase):
...
@@ -1273,6 +1297,7 @@ class TestRelu6API(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out1
=
F
.
relu6
(
x
)
out1
=
F
.
relu6
(
x
)
...
@@ -1296,6 +1321,7 @@ class TestRelu6API(unittest.TestCase):
...
@@ -1296,6 +1321,7 @@ class TestRelu6API(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out
=
fluid
.
layers
.
relu6
(
x
)
out
=
fluid
.
layers
.
relu6
(
x
)
...
@@ -1305,6 +1331,7 @@ class TestRelu6API(unittest.TestCase):
...
@@ -1305,6 +1331,7 @@ class TestRelu6API(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
relu6
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
relu6
,
1
)
...
@@ -1424,11 +1451,13 @@ class TestELU(TestActivation):
...
@@ -1424,11 +1451,13 @@ class TestELU(TestActivation):
class
TestELUAPI
(
unittest
.
TestCase
):
class
TestELUAPI
(
unittest
.
TestCase
):
# test paddle.nn.ELU, paddle.nn.functional.elu
# test paddle.nn.ELU, paddle.nn.functional.elu
def
setUp
(
self
):
def
setUp
(
self
):
np
.
random
.
seed
(
1024
)
self
.
x_np
=
np
.
random
.
uniform
(
-
3
,
3
,
[
10
,
12
]).
astype
(
'float32'
)
self
.
x_np
=
np
.
random
.
uniform
(
-
3
,
3
,
[
10
,
12
]).
astype
(
'float32'
)
self
.
place
=
paddle
.
CUDAPlace
(
0
)
if
core
.
is_compiled_with_cuda
()
\
self
.
place
=
paddle
.
CUDAPlace
(
0
)
if
core
.
is_compiled_with_cuda
()
\
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
x
=
paddle
.
data
(
'X'
,
[
10
,
12
])
out1
=
F
.
elu
(
x
)
out1
=
F
.
elu
(
x
)
...
@@ -1459,6 +1488,7 @@ class TestELUAPI(unittest.TestCase):
...
@@ -1459,6 +1488,7 @@ class TestELUAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
elu
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
elu
,
1
)
...
@@ -1747,6 +1777,7 @@ class TestSoftplusAPI(unittest.TestCase):
...
@@ -1747,6 +1777,7 @@ class TestSoftplusAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out1
=
F
.
softplus
(
x
,
self
.
beta
,
self
.
threshold
)
out1
=
F
.
softplus
(
x
,
self
.
beta
,
self
.
threshold
)
...
@@ -1770,6 +1801,7 @@ class TestSoftplusAPI(unittest.TestCase):
...
@@ -1770,6 +1801,7 @@ class TestSoftplusAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out
=
fluid
.
layers
.
softplus
(
x
)
out
=
fluid
.
layers
.
softplus
(
x
)
...
@@ -1779,6 +1811,7 @@ class TestSoftplusAPI(unittest.TestCase):
...
@@ -1779,6 +1811,7 @@ class TestSoftplusAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
softplus
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
softplus
,
1
)
...
@@ -1820,6 +1853,7 @@ class TestSoftsignAPI(unittest.TestCase):
...
@@ -1820,6 +1853,7 @@ class TestSoftsignAPI(unittest.TestCase):
else
paddle
.
CPUPlace
()
else
paddle
.
CPUPlace
()
def
test_static_api
(
self
):
def
test_static_api
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
paddle
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out1
=
F
.
softsign
(
x
)
out1
=
F
.
softsign
(
x
)
...
@@ -1843,6 +1877,7 @@ class TestSoftsignAPI(unittest.TestCase):
...
@@ -1843,6 +1877,7 @@ class TestSoftsignAPI(unittest.TestCase):
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
x
=
fluid
.
data
(
'X'
,
self
.
x_np
.
shape
,
self
.
x_np
.
dtype
)
out
=
fluid
.
layers
.
softsign
(
x
)
out
=
fluid
.
layers
.
softsign
(
x
)
...
@@ -1852,6 +1887,7 @@ class TestSoftsignAPI(unittest.TestCase):
...
@@ -1852,6 +1887,7 @@ class TestSoftsignAPI(unittest.TestCase):
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
self
.
assertEqual
(
np
.
allclose
(
out_ref
,
res
[
0
]),
True
)
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
# The input type must be Variable.
# The input type must be Variable.
self
.
assertRaises
(
TypeError
,
F
.
softsign
,
1
)
self
.
assertRaises
(
TypeError
,
F
.
softsign
,
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录