Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
3948b58b
P
Paddle
项目概览
机器未来
/
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看板
提交
3948b58b
编写于
4月 28, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unittest of cross entropy. It is not stable on CUDA
上级
faa7e485
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
0 deletion
+56
-0
python/paddle/fluid/tests/unittests/test_cross_entropy_op.py
python/paddle/fluid/tests/unittests/test_cross_entropy_op.py
+56
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_cross_entropy_op.py
浏览文件 @
3948b58b
...
...
@@ -15,6 +15,7 @@
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
,
randomize_probability
import
paddle.fluid
as
fluid
class
TestCrossEntropyOp1
(
OpTest
):
...
...
@@ -105,5 +106,60 @@ class TestCrossEntropyOp3(OpTest):
[
"X"
],
"Y"
,
max_relative_error
=
0.05
,
numeric_grad_delta
=
0.001
)
class
TestCrossEntropyStable
(
unittest
.
TestCase
):
def
main
(
self
,
place
):
if
isinstance
(
place
,
fluid
.
CUDAPlace
)
and
not
fluid
.
core
.
is_compiled_with_cuda
():
return
class
DataRandom
(
object
):
def
__init__
(
self
):
self
.
random
=
np
.
random
.
RandomState
(
seed
=
1
)
def
next
(
self
):
return
{
'input'
:
self
.
random
.
uniform
(
low
=-
1
,
high
=
1
,
size
=
(
64
,
200
)).
astype
(
'float32'
),
'label'
:
self
.
random
.
uniform
(
low
=
0
,
high
=
10000
,
size
=
(
64
,
1
)).
astype
(
'int64'
),
}
losses
=
[]
for
_
in
xrange
(
2
):
startup
=
fluid
.
Program
()
startup
.
random_seed
=
1
main
=
fluid
.
Program
()
scope
=
fluid
.
core
.
Scope
()
with
fluid
.
scope_guard
(
scope
):
with
fluid
.
program_guard
(
main
,
startup
):
img
=
fluid
.
layers
.
data
(
'input'
,
shape
=
[
200
])
label
=
fluid
.
layers
.
data
(
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
prediction
=
fluid
.
layers
.
fc
(
input
=
img
,
size
=
10000
,
act
=
'softmax'
)
xe
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
loss
=
fluid
.
layers
.
mean
(
xe
)
adam
=
fluid
.
optimizer
.
Adam
()
adam
.
minimize
(
loss
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
startup
)
data
=
DataRandom
()
for
i
in
xrange
(
1000
):
exe
.
run
(
feed
=
next
(
data
))
losses
.
append
(
exe
.
run
(
feed
=
next
(
data
),
fetch_list
=
[
loss
])[
0
])
print
losses
self
.
assertAlmostEqual
(
losses
[
0
][
0
],
losses
[
1
][
0
])
def
test_cpu
(
self
):
self
.
main
(
fluid
.
CPUPlace
())
def
test_cuda
(
self
):
self
.
main
(
fluid
.
CUDAPlace
(
0
))
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录