Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0d82baf8
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看板
提交
0d82baf8
编写于
1月 10, 2020
作者:
S
songyouwei
提交者:
Tao Luo
1月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add batch_size_1_input data function for sequence ops unittests (#22172)
上级
2f3e2a84
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
52 addition
and
19 deletion
+52
-19
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+2
-2
python/paddle/fluid/tests/unittests/op_test.py
python/paddle/fluid/tests/unittests/op_test.py
+18
-0
python/paddle/fluid/tests/unittests/sequence/test_sequence_conv.py
...ddle/fluid/tests/unittests/sequence/test_sequence_conv.py
+0
-0
python/paddle/fluid/tests/unittests/sequence/test_sequence_pool.py
...ddle/fluid/tests/unittests/sequence/test_sequence_pool.py
+29
-14
python/paddle/fluid/tests/unittests/test_fusion_seqconv_eltadd_relu_op.py
...uid/tests/unittests/test_fusion_seqconv_eltadd_relu_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_fusion_seqpool_concat_op.py
...le/fluid/tests/unittests/test_fusion_seqpool_concat_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_fusion_seqpool_cvm_concat_op.py
...luid/tests/unittests/test_fusion_seqpool_cvm_concat_op.py
+1
-1
未找到文件。
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
0d82baf8
...
...
@@ -207,8 +207,8 @@ set(TEST_OPS_WITH_GC
test_pad2d_op
test_scatter_op
test_sequence_concat
test_seq_conv
test_seq_pool
test_seq
uence
_conv
test_seq
uence
_pool
test_sequence_expand_as
test_sequence_expand
test_sequence_pad_op
...
...
python/paddle/fluid/tests/unittests/op_test.py
浏览文件 @
0d82baf8
...
...
@@ -374,6 +374,24 @@ class OpTest(unittest.TestCase):
else
:
return
fluid
.
dygraph
.
base
.
to_variable
(
value
)
def
get_sequence_batch_size_1_input
(
self
,
lod
=
None
,
shape
=
None
):
"""Get LoD input data whose batch size is 1.
All sequence related OP unittests should call this function to contain the case of batch size = 1.
Args:
lod (list[list of int], optional): Length-based LoD, length of lod[0] should be 1. Default: [[13]].
shape (list, optional): Shape of input, shape[0] should be equals to lod[0][0]. Default: [13, 23].
Returns:
tuple (ndarray, lod) : LoD input data whose batch size is 1.
"""
if
lod
is
None
:
lod
=
[[
13
]]
if
shape
is
None
:
shape
=
[
13
,
23
]
assert
len
(
lod
[
0
])
==
1
assert
lod
[
0
][
0
]
==
shape
[
0
]
x
=
np
.
random
.
uniform
(
0.1
,
1
,
shape
).
astype
(
'float32'
)
return
(
x
,
lod
)
def
append_input_output_for_dygraph
(
self
,
op_proto
,
np_list
,
is_input
,
if_return_inputs_grad_dict
,
block
):
def
create_var
(
np_value
,
name
,
is_input
,
if_return_inputs_grad_dict
):
...
...
python/paddle/fluid/tests/unittests/sequence/test_seq_conv.py
→
python/paddle/fluid/tests/unittests/sequence/test_seq
uence
_conv.py
浏览文件 @
0d82baf8
文件已移动
python/paddle/fluid/tests/unittests/sequence/test_seq_pool.py
→
python/paddle/fluid/tests/unittests/sequence/test_seq
uence
_pool.py
浏览文件 @
0d82baf8
...
...
@@ -57,26 +57,30 @@ class TestSeqAvgPool(OpTest):
def
set_lod
(
self
):
return
[[
11
]]
def
set_data
(
self
):
self
.
op_type
=
'sequence_pool'
def
set_lod_data
(
self
):
x
=
np
.
random
.
uniform
(
0.1
,
1
,
[
11
,
23
]).
astype
(
'float32'
)
return
x
def
set_data
(
self
):
x
=
self
.
set_lod_data
()
lod
=
self
.
set_lod
()
level
=
len
(
lod
)
-
1
self
.
inputs
=
{
'X'
:
(
x
,
lod
)}
offset
=
convert_to_offset
(
lod
)
out
=
np
.
zeros
((
len
(
lod
[
level
]),
23
)).
astype
(
'float32'
)
out
=
np
.
zeros
((
len
(
lod
[
level
]),
x
.
shape
[
1
]
)).
astype
(
'float32'
)
self
.
outputs
=
{
'Out'
:
out
}
return
x
,
offset
,
out
return
x
,
lod
,
offset
,
out
def
compute
(
self
,
x
,
offset
,
out
):
self
.
attrs
=
{
"pad_value"
:
0.0
,
'pooltype'
:
"AVERAGE"
}
compute_seqpool_avg
(
x
,
offset
,
out
,
self
.
attrs
[
"pad_value"
])
def
setUp
(
self
):
x
,
offset
,
out
=
self
.
set_data
()
self
.
op_type
=
'sequence_pool'
x
,
lod
,
offset
,
out
=
self
.
set_data
()
self
.
compute
(
x
,
offset
,
out
)
if
len
(
offset
)
>
1
:
self
.
outputs
=
{
'Out'
:
(
out
,
[
self
.
set_lod
()
[
0
]])}
self
.
outputs
=
{
'Out'
:
(
out
,
[
lod
[
0
]])}
def
test_check_output
(
self
):
self
.
check_output
(
check_dygraph
=
False
)
...
...
@@ -90,6 +94,17 @@ class TestSeqAvgPool(OpTest):
self
.
check_grad
([
"X"
],
"Out"
,
check_dygraph
=
False
)
class
TestSeqAvgPoolBatch1
(
TestSeqAvgPool
):
def
set_lod
(
self
):
return
[[
11
]]
def
set_lod_data
(
self
):
lod
=
self
.
set_lod
()
x
,
_
=
self
.
get_sequence_batch_size_1_input
(
lod
=
lod
,
shape
=
[
lod
[
0
][
0
],
23
])
return
x
class
TestSeqAvgPoolLen0
(
TestSeqAvgPool
):
def
set_lod
(
self
):
return
[[
0
,
4
,
0
,
7
,
0
]]
...
...
@@ -135,7 +150,7 @@ class TestSeqMaxPool(TestSeqAvgPool):
out
=
np
.
zeros
((
len
(
lod
[
level
]),
23
)).
astype
(
'float32'
)
self
.
outputs
=
{
'Out'
:
out
}
return
x
,
offset
,
out
return
x
,
lod
,
offset
,
out
def
compute
(
self
,
x
,
offset
,
out
):
self
.
attrs
=
{
"pad_value"
:
0.5
,
'pooltype'
:
"MAX"
}
...
...
@@ -232,7 +247,7 @@ class TestSeqAvgPool2D(TestSeqAvgPool):
out
=
np
.
zeros
((
len
(
lod
[
level
]),
3
,
17
)).
astype
(
'float32'
)
self
.
outputs
=
{
'Out'
:
out
}
return
x
,
offset
,
out
return
x
,
lod
,
offset
,
out
def
compute
(
self
,
x
,
offset
,
out
):
self
.
attrs
=
{
"pad_value"
:
0.0
,
'pooltype'
:
"AVERAGE"
}
...
...
@@ -321,19 +336,19 @@ class TestSeqMaxPool2D(TestSeqAvgPool2D):
def
set_data
(
self
):
self
.
op_type
=
'sequence_pool'
x
=
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
3
,
11
]).
astype
(
'float32'
)
self
.
lod
=
self
.
set_lod
()
level
=
len
(
self
.
lod
)
-
1
self
.
inputs
=
{
'X'
:
(
x
,
self
.
lod
)}
offset
=
convert_to_offset
(
self
.
lod
)
lod
=
self
.
set_lod
()
level
=
len
(
lod
)
-
1
self
.
inputs
=
{
'X'
:
(
x
,
lod
)}
offset
=
convert_to_offset
(
lod
)
for
i
in
range
(
len
(
offset
[
level
])
-
1
):
l
=
offset
[
level
][
i
+
1
]
-
offset
[
level
][
i
]
if
l
==
0
:
continue
x
[
offset
[
level
][
i
]
+
np
.
random
.
randint
(
l
),
:]
+=
1.0
out
=
np
.
zeros
((
len
(
self
.
lod
[
level
]),
3
,
11
)).
astype
(
'float32'
)
out
=
np
.
zeros
((
len
(
lod
[
level
]),
3
,
11
)).
astype
(
'float32'
)
self
.
outputs
=
{
'Out'
:
out
}
return
x
,
offset
,
out
return
x
,
lod
,
offset
,
out
def
compute
(
self
,
x
,
offset
,
out
):
self
.
attrs
=
{
"pad_value"
:
0.0
,
'pooltype'
:
"MAX"
}
...
...
python/paddle/fluid/tests/unittests/test_fusion_seqconv_eltadd_relu_op.py
浏览文件 @
0d82baf8
...
...
@@ -18,7 +18,7 @@ import unittest
import
numpy
as
np
import
random
from
op_test
import
OpTest
from
sequence.test_seq_conv
import
seqconv
from
sequence.test_seq
uence
_conv
import
seqconv
class
TestSeqConvEltAddRelu
(
OpTest
):
...
...
python/paddle/fluid/tests/unittests/test_fusion_seqpool_concat_op.py
浏览文件 @
0d82baf8
...
...
@@ -18,7 +18,7 @@ import unittest
import
numpy
as
np
from
op_test
import
OpTest
from
test_reorder_lod_tensor
import
convert_to_offset
from
sequence.test_seq_pool
import
compute_seqpool_sum
,
compute_seqpool_avg
,
compute_seqpool_sqrt
from
sequence.test_seq
uence
_pool
import
compute_seqpool_sum
,
compute_seqpool_avg
,
compute_seqpool_sqrt
class
TestFusionSeqPoolConcatOp
(
OpTest
):
...
...
python/paddle/fluid/tests/unittests/test_fusion_seqpool_cvm_concat_op.py
浏览文件 @
0d82baf8
...
...
@@ -18,7 +18,7 @@ import unittest
import
numpy
as
np
from
op_test
import
OpTest
from
test_reorder_lod_tensor
import
convert_to_offset
from
sequence.test_seq_pool
import
compute_seqpool_sum
,
compute_seqpool_avg
,
compute_seqpool_sqrt
from
sequence.test_seq
uence
_pool
import
compute_seqpool_sum
,
compute_seqpool_avg
,
compute_seqpool_sqrt
from
test_cvm_op
import
cvm_compute
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录