Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
bd29052e
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看板
未验证
提交
bd29052e
编写于
12月 11, 2020
作者:
L
lijianshe02
提交者:
GitHub
12月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix random seed in nll_loss unitest test=develop (#29538)
* fix random seed in nll_loss unitest test=develop
上级
0ce6d7fa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
0 deletion
+19
-0
python/paddle/fluid/tests/unittests/test_nll_loss.py
python/paddle/fluid/tests/unittests/test_nll_loss.py
+19
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_nll_loss.py
浏览文件 @
bd29052e
...
...
@@ -72,6 +72,7 @@ def nll_loss_2d(logs, targets, weight=None, reduction='mean',
class
TestNLLLoss
(
unittest
.
TestCase
):
def
test_NLLLoss_1D_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
prog
=
fluid
.
Program
()
...
...
@@ -105,6 +106,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_1D_sum
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
prog
=
fluid
.
Program
()
...
...
@@ -138,6 +140,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_1D_with_weight_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
10
,
)).
astype
(
np
.
float64
)
...
...
@@ -176,6 +179,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_1D_with_weight_sum
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
10
,
)).
astype
(
np
.
float64
)
...
...
@@ -215,6 +219,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_1D_with_weight_mean_cpu
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
10
,
)).
astype
(
np
.
float64
)
...
...
@@ -251,6 +256,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_1D_with_weight_no_reduce_cpu
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
10
,
10
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
10
,
size
=
(
10
,
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
10
,
)).
astype
(
np
.
float64
)
...
...
@@ -288,6 +294,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_2D_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
)).
astype
(
np
.
int64
)
prog
=
fluid
.
Program
()
...
...
@@ -323,6 +330,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_2D_sum
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
)).
astype
(
np
.
int64
)
prog
=
fluid
.
Program
()
...
...
@@ -358,6 +366,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_2D_with_weight_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -399,6 +408,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_2D_with_weight_mean_cpu
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -438,6 +448,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_2D_with_weight_sum
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -479,6 +490,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_in_dims_not_2or4_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
,
5
)).
astype
(
np
.
int64
)
prog
=
fluid
.
Program
()
...
...
@@ -519,6 +531,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_in_dims_not_2or4_with_weight_mean
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -565,6 +578,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_in_dims_not_2or4_with_weight_sum
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -614,6 +628,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_in_dims_not_2or4_with_weight_no_reduce
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -664,6 +679,7 @@ class TestNLLLoss(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
dy_result
,
expected
))
def
test_NLLLoss_in_dims_not_2or4_with_weight_no_reduce_cpu
(
self
):
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
random
(
size
=
(
5
,
3
,
5
,
5
,
5
)).
astype
(
np
.
float64
)
label_np
=
np
.
random
.
randint
(
0
,
3
,
size
=
(
5
,
5
,
5
,
5
)).
astype
(
np
.
int64
)
weight_np
=
np
.
random
.
random
(
size
=
(
3
,
)).
astype
(
np
.
float64
)
...
...
@@ -717,6 +733,7 @@ class TestNLLLossOp1DWithReduce(OpTest):
self
.
init_test_case
()
self
.
op_type
=
"nll_loss"
self
.
with_weight
=
False
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
uniform
(
0.1
,
0.8
,
self
.
input_shape
).
astype
(
"float64"
)
label_np
=
np
.
random
.
randint
(
0
,
self
.
input_shape
[
1
],
...
...
@@ -758,6 +775,7 @@ class TestNLLLossOp1DNoReduce(OpTest):
self
.
init_test_case
()
self
.
op_type
=
"nll_loss"
self
.
with_weight
=
False
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
uniform
(
0.1
,
0.8
,
self
.
input_shape
).
astype
(
"float64"
)
label_np
=
np
.
random
.
randint
(
0
,
self
.
input_shape
[
1
],
...
...
@@ -844,6 +862,7 @@ class TestNLLLossOp2DNoReduce(OpTest):
self
.
init_test_case
()
self
.
op_type
=
"nll_loss"
self
.
with_weight
=
False
np
.
random
.
seed
(
200
)
input_np
=
np
.
random
.
uniform
(
0.1
,
0.8
,
self
.
input_shape
).
astype
(
"float64"
)
label_np
=
np
.
random
.
randint
(
0
,
self
.
input_shape
[
1
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录