Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
9cb455fa
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9cb455fa
编写于
8月 27, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update function
上级
0fb5e351
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
20 addition
and
36 deletion
+20
-36
paddle/fluid/operators/math/sequence_padding.cc
paddle/fluid/operators/math/sequence_padding.cc
+0
-9
paddle/fluid/operators/math/sequence_padding.cu
paddle/fluid/operators/math/sequence_padding.cu
+0
-8
paddle/fluid/operators/sequence_pad_op.cc
paddle/fluid/operators/sequence_pad_op.cc
+18
-14
python/paddle/fluid/tests/unittests/test_sequence_pad_op.py
python/paddle/fluid/tests/unittests/test_sequence_pad_op.py
+2
-5
未找到文件。
paddle/fluid/operators/math/sequence_padding.cc
浏览文件 @
9cb455fa
...
...
@@ -98,15 +98,6 @@ class PaddingLoDTensorFunctor<platform::CPUDeviceContext, T> {
CopyValidData
<
T
>
(
pad_tensor
,
&
seq_tensor
,
seq_offsets
,
pad_seq_len
,
step_width
,
norm_by_times
,
kSeqToPad
,
layout
);
// Set pad_tensor's lod info if possible
if
(
layout
==
kBatchLengthWidth
)
{
framework
::
LoD
pad_lod
(
seq_lod
.
begin
()
+
lod_level
,
seq_lod
.
end
());
for
(
size_t
i
=
0
;
i
<
pad_lod
[
0
].
size
();
++
i
)
{
pad_lod
[
0
][
i
]
=
i
*
pad_seq_len
;
}
pad_tensor
->
set_lod
(
pad_lod
);
}
}
};
...
...
paddle/fluid/operators/math/sequence_padding.cu
浏览文件 @
9cb455fa
...
...
@@ -106,14 +106,6 @@ class PaddingLoDTensorFunctor<platform::CUDADeviceContext, T> {
pad_data
,
seq_data
,
pad_value_data
,
pad_value
.
numel
()
==
1
,
seq_offsets
.
CUDAData
(
context
.
GetPlace
()),
seq_num
,
pad_seq_len
,
step_width
,
norm_by_times
,
layout
);
if
(
layout
==
kBatchLengthWidth
)
{
framework
::
LoD
pad_lod
(
seq_lod
.
begin
()
+
lod_level
,
seq_lod
.
end
());
for
(
size_t
i
=
0
;
i
<
pad_lod
[
0
].
size
();
++
i
)
{
pad_lod
[
0
][
i
]
=
i
*
pad_seq_len
;
}
pad_tensor
->
set_lod
(
pad_lod
);
}
}
};
...
...
paddle/fluid/operators/sequence_pad_op.cc
浏览文件 @
9cb455fa
...
...
@@ -40,7 +40,8 @@ class SequencePadOp : public framework::OperatorWithKernel {
"The Input(PadValue) must be a scalar or a tensor whose "
"shape equals to time steps in sequences"
);
int
batch_dim_size
=
-
1
;
int
out_dim_0
=
-
1
;
int
out_dim_1
=
-
1
;
if
(
ctx
->
IsRuntime
())
{
// run time
...
...
@@ -64,7 +65,8 @@ class SequencePadOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_GE
(
padded_length
,
max_seq_len
,
"The Attr(padded_length) must be -1 or an int greater "
"than the length of the longest original sequence."
);
batch_dim_size
=
padded_length
*
seq_num
;
out_dim_0
=
seq_num
;
out_dim_1
=
padded_length
;
}
else
{
// compile time
framework
::
VarDesc
*
x_desc
=
...
...
@@ -72,9 +74,11 @@ class SequencePadOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_GE
(
x_desc
->
GetLoDLevel
(),
1
);
}
auto
out_dims
=
x_dims
;
out_dims
[
0
]
=
batch_dim_size
;
ctx
->
SetOutputDim
(
"Out"
,
out_dims
);
std
::
vector
<
int
>
out_dims_vec
{
out_dim_0
,
out_dim_1
};
auto
time_step_dims_vec
=
framework
::
vectorize2int
(
time_step_dims
);
out_dims_vec
.
insert
(
out_dims_vec
.
end
(),
time_step_dims_vec
.
begin
(),
time_step_dims_vec
.
end
());
ctx
->
SetOutputDim
(
"Out"
,
framework
::
make_ddim
(
out_dims_vec
));
}
};
...
...
@@ -118,9 +122,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
and Input(PadValue):
PadValue.data = [0]
and attribite 'padded_length' = 4,
then we get
1-level
LoDTensor:
Out.
lod = [[0, 4, 8]]
Out.data = [a, b, 0, 0, c, d, e, 0
]
then we get LoDTensor:
Out.
data = [[a, b, 0, 0],
[c, d, e, 0]
]
Case 2:
...
...
@@ -131,9 +135,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
PadValue.data = [0]
and attribite 'padded_length' = -1, which mean using the length
of longest input sequence(3 in this case),
then we get
1-level
LoDTensor:
Out.
lod = [[0, 3, 6]]
Out.data = [[a1, a2], [b1, b2], [0, 0], [c1, c2], [d1, d2], [e1, e2
]]
then we get LoDTensor:
Out.
data = [[[a1, a2], [b1, b2], [0, 0]],
[[c1, c2], [d1, d2], [e1, e2]
]]
Case 3:
...
...
@@ -144,9 +148,9 @@ class SequencePadOpMaker : public framework::OpProtoAndCheckerMaker {
PadValue.data = [p1, p2]
and attribite 'padded_length' = -1, which mean using the length
of longest input sequence(3 in this case),
then we get
1-level
LoDTensor:
Out.
lod = [[0, 3, 6]]
Out.data = [[a1, a2], [b1, b2], [p1, p2], [c1, c2], [d1, d2], [e1, e2
]]
then we get LoDTensor:
Out.
data = [[[a1, a2], [b1, b2], [p1, p2]],
[[c1, c2], [d1, d2], [e1, e2]
]]
)DOC"
);
}
...
...
python/paddle/fluid/tests/unittests/test_sequence_pad_op.py
浏览文件 @
9cb455fa
...
...
@@ -61,11 +61,8 @@ class TestSequencePadOp(OpTest):
padded_sequences
.
append
(
seq
)
start_idx
=
end_idx
out_len_lod
=
self
.
x_len_lod
[:]
out_len_lod_0
=
[
padded_length
]
*
len
(
x_len_lod_0
)
out_len_lod
[
0
]
=
out_len_lod_0
out_data
=
np
.
concatenate
(
padded_sequences
,
axis
=
0
)
self
.
outputs
=
{
'Out'
:
(
out_data
,
out_len_lod
)}
out_data
=
np
.
array
(
padded_sequences
)
self
.
outputs
=
{
'Out'
:
out_data
}
def
setUp
(
self
):
self
.
op_type
=
'sequence_pad'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录