Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
9a18e78e
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看板
提交
9a18e78e
编写于
11月 14, 2017
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update sequence slice op, fix some error
上级
29c25828
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
15 deletion
+26
-15
paddle/operators/sequence_slice_op.cc
paddle/operators/sequence_slice_op.cc
+9
-6
paddle/operators/sequence_slice_op.h
paddle/operators/sequence_slice_op.h
+3
-2
python/paddle/v2/fluid/tests/test_sequence_slice_op.py
python/paddle/v2/fluid/tests/test_sequence_slice_op.py
+14
-7
未找到文件。
paddle/operators/sequence_slice_op.cc
浏览文件 @
9a18e78e
...
...
@@ -75,14 +75,17 @@ class SequenceSliceOpMaker : public framework::OpProtoAndCheckerMaker {
"the input of SequenceSliceOp."
);
AddInput
(
"Offset"
,
"(Tensor), "
"A vector<int> to describes offset for sub sequence item."
);
"a vector<int> to describe the offset of every input sequence for "
"sub sequence item."
);
AddInput
(
"Length"
,
"(Tensor), "
"A vector<int> to describes length for sub sequence item."
);
"a vector<int> to describe the length of every input sequence for "
"sub sequence item."
);
AddOutput
(
"Out"
,
"(LoDTensor),
output of sequence slice
Op."
);
"(LoDTensor),
The output of SequenceSlice
Op."
);
AddComment
(
R"DOC(
Sequence slice operator
The operator crop a subsequence from given sequence with given start offset and subsequence length.
It only supports sequence (LoD Tensor with level number is 1).
- Case:
...
...
@@ -91,13 +94,13 @@ It only supports sequence (LoD Tensor with level number is 1).
c1, c2]
[d1, d2;
e1, e2]]
LoD(X) = {{0, 3, 5}}; Dims(X) = (
4, 1
, 2)
Offset =
(0, 1); Length = (2, 1)
LoD(X) = {{0, 3, 5}}; Dims(X) = (
5
, 2)
Offset =
[0, 1]; Length = [2, 1]
Out = [[a1, a2;
b1, b2]
[e1, e2]]
LoD(Out) = {{0, 2, 3}}
LoD(Out) = {{0, 2, 3}}
; Dims(Out) = (3, 2)
NOTE: The length of the input, offset and length should be the same. The offset start from 0.
)DOC"
);
}
...
...
paddle/operators/sequence_slice_op.h
浏览文件 @
9a18e78e
...
...
@@ -87,9 +87,10 @@ class SequenceSliceOpKernel : public framework::OpKernel<T> {
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
out_lod
=
SequenceSliceLoD
(
*
in
,
offset_data
,
length_data
);
auto
out_dims
=
in
->
dims
();
out_dims
[
0
]
=
out_lod
[
0
][
out_lod
[
0
].
size
()
-
1
];
out
->
Resize
(
out_dims
);
out
->
set_lod
(
out_lod
);
math
::
SetConstant
<
Place
,
T
>
set_zero
;
set_zero
(
ctx
.
device_context
(),
out
,
static_cast
<
T
>
(
0
));
auto
in_stride
=
framework
::
stride
(
in
->
dims
());
auto
out_stride
=
framework
::
stride
(
out
->
dims
());
...
...
python/paddle/v2/f
ramework
/tests/test_sequence_slice_op.py
→
python/paddle/v2/f
luid
/tests/test_sequence_slice_op.py
浏览文件 @
9a18e78e
...
...
@@ -5,25 +5,32 @@ from op_test import OpTest
class
TestSequenceSliceOp
(
OpTest
):
def
set_data
(
self
):
self
.
init_test_case
()
# only supprot one level LoD
x
=
np
.
random
.
random
(
(
100
,
3
,
2
)
).
astype
(
'float32'
)
lod
=
[[
0
,
20
,
40
,
60
,
80
,
100
]]
offset
=
np
.
array
(
[
1
,
2
,
3
,
4
,
5
]
).
flatten
().
astype
(
"int64"
)
length
=
np
.
array
(
[
10
,
8
,
6
,
4
,
2
]
).
flatten
().
astype
(
"int64"
)
x
=
np
.
random
.
random
(
self
.
x_dim
).
astype
(
'float32'
)
lod
=
self
.
x_lod
offset
=
np
.
array
(
self
.
offset
).
flatten
().
astype
(
"int64"
)
length
=
np
.
array
(
self
.
length
).
flatten
().
astype
(
"int64"
)
self
.
inputs
=
{
'X'
:
(
x
,
lod
),
'Offset'
:
offset
,
'Length'
:
length
}
outs
=
np
.
zeros
((
100
,
3
,
2
)).
astype
(
'float32'
)
outs
=
[]
#
np.zeros((100, 3, 2)).astype('float32')
out_lod
=
[[
0
]]
out_lod_offset
=
0
for
i
in
range
(
len
(
offset
)):
sub_x
=
x
[
lod
[
0
][
i
]
+
offset
[
i
]:
lod
[
0
]
[
i
]
+
offset
[
i
]
+
length
[
i
],
:]
out_lod_offset
=
out_lod_offset
+
len
(
sub_x
)
outs
[
out_lod
[
0
][
i
]:
out_lod_offset
,
:]
=
sub_x
outs
.
append
(
sub_x
)
out_lod
[
0
].
append
(
out_lod_offset
)
outs
=
np
.
concatenate
(
outs
,
axis
=
0
)
self
.
outputs
=
{
'Out'
:
(
outs
,
out_lod
)}
def
init_test_case
(
self
):
self
.
x_dim
=
(
100
,
3
,
2
)
self
.
x_lod
=
[[
0
,
20
,
40
,
60
,
80
,
100
]]
self
.
offset
=
[
1
,
2
,
3
,
4
,
5
]
self
.
length
=
[
10
,
8
,
6
,
4
,
2
]
def
setUp
(
self
):
self
.
op_type
=
"sequence_slice"
self
.
set_data
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录