Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
8d4e2d4c
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看板
提交
8d4e2d4c
编写于
10月 30, 2017
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. Add unitest for empty sequence case
2. Fix comments and paddle enforce check
上级
9f32b61c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
38 addition
and
11 deletion
+38
-11
paddle/operators/seq_expand_op.cc
paddle/operators/seq_expand_op.cc
+25
-7
paddle/operators/seq_expand_op.h
paddle/operators/seq_expand_op.h
+13
-4
未找到文件。
paddle/operators/seq_expand_op.cc
浏览文件 @
8d4e2d4c
...
@@ -25,10 +25,8 @@ class SeqExpandOp : public framework::OperatorWithKernel {
...
@@ -25,10 +25,8 @@ class SeqExpandOp : public framework::OperatorWithKernel {
protected:
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
));
"Input(X) of SeqExpandOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
));
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of SeqExpandOp should not be null."
);
PADDLE_ENFORCE
(
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Y"
),
ctx
->
HasInput
(
"Y"
),
"Input(Y) of SeqExpandOp should not be null while repeat == 0."
);
"Input(Y) of SeqExpandOp should not be null while repeat == 0."
);
...
@@ -54,7 +52,7 @@ class SeqExpandOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -54,7 +52,7 @@ class SeqExpandOpMaker : public framework::OpProtoAndCheckerMaker {
"The element numbers of last level in input('Y') "
"The element numbers of last level in input('Y') "
"must be equal to dims[0] of input('X')."
);
"must be equal to dims[0] of input('X')."
);
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
"The output of seq_expand op."
"
(LodTensor)
The output of seq_expand op."
"The lod of output will be as same as input(Y)'s lod."
);
"The lod of output will be as same as input(Y)'s lod."
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Expand input(X) according to LOD of input(Y).
Expand input(X) according to LOD of input(Y).
...
@@ -69,6 +67,7 @@ Given 2-level a LoDTensor input(X)
...
@@ -69,6 +67,7 @@ Given 2-level a LoDTensor input(X)
and input(Y)
and input(Y)
Y.lod = [[0, 2, 4],
Y.lod = [[0, 2, 4],
[0, 3, 6, 7, 8]]
[0, 3, 6, 7, 8]]
with condition len(Y.lod[-1]) -1 == X.dims[0]
then we get 2-level LoDTensor
then we get 2-level LoDTensor
Out.lod = [[0, 2, 4],
Out.lod = [[0, 2, 4],
[0, 3, 6, 7, 8]]
[0, 3, 6, 7, 8]]
...
@@ -83,6 +82,7 @@ Given a 0-level LoDTensor input(X)
...
@@ -83,6 +82,7 @@ Given a 0-level LoDTensor input(X)
X.dims = [3, 1]
X.dims = [3, 1]
and input(Y)
and input(Y)
Y.lod = [[0, 2, 3, 6]]
Y.lod = [[0, 2, 3, 6]]
with condition len(Y.lod[-1]) -1 == X.dims[0]
then we get 1-level LoDTensor
then we get 1-level LoDTensor
Out.lod = [[0, 2, 3, 6]]
Out.lod = [[0, 2, 3, 6]]
Out.data = [a, a, b, c, c, c]
Out.data = [a, a, b, c, c, c]
...
@@ -96,11 +96,29 @@ Given a 0-level LoDTensor input(X)
...
@@ -96,11 +96,29 @@ Given a 0-level LoDTensor input(X)
X.dims = [3, 2]
X.dims = [3, 2]
and input(Y)
and input(Y)
Y.lod = [[0, 2, 3, 6]]
Y.lod = [[0, 2, 3, 6]]
with condition len(Y.lod[-1]) -1 == X.dims[0]
then we get 1-level LoDTensor
then we get 1-level LoDTensor
Out.lod = [[0, 2, 3, 6]]
Out.lod = [[0, 2, 3, 6]]
Out.data = [[a,b], [a,b] [c,d], [e, f], [e, f], [e, f]]
Out.data = [[a,b], [a,b] [c,d], [e, f], [e, f], [e, f]]
Out.dims = [6, 2]
Out.dims = [6, 2]
Case 4:
Given 2-level a LoDTensor input(X)
X.lod = [[0, 2, 3],
[0, 1, 3, 4]]
X.data = [a, b, c, d]
X.dims = [4, 1]
and input(Y)
Y.lod = [[0, 2, 4],
[0, 3, 6, 6, 8]]
with condition len(Y.lod[-1]) -1 == X.dims[0]
then we get 2-level LoDTensor
Out.lod = [[0, 2, 4],
[0, 3, 6, 6, 8]]
Out.data = [a, a, a, b, b, b, d, d]
Out.dims = [8, 1]
)DOC"
);
)DOC"
);
}
}
...
@@ -112,8 +130,8 @@ class SeqExpandOpGrad : public framework::OperatorWithKernel {
...
@@ -112,8 +130,8 @@ class SeqExpandOpGrad : public framework::OperatorWithKernel {
protected:
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
)
,
"Input(X) should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
));
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Out"
)
,
"Input(Out) should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Out"
));
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) should not be null"
);
"Input(Out@GRAD) should not be null"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
...
...
paddle/operators/seq_expand_op.h
浏览文件 @
8d4e2d4c
...
@@ -36,7 +36,6 @@ class SeqExpandKernel : public framework::OpKernel<T> {
...
@@ -36,7 +36,6 @@ class SeqExpandKernel : public framework::OpKernel<T> {
"The size of last lod level in Input(Y)"
"The size of last lod level in Input(Y)"
"must be equal to dims[0] of Input(X)."
);
"must be equal to dims[0] of Input(X)."
);
out
->
set_lod
(
y
->
lod
());
out
->
set_lod
(
y
->
lod
());
out
->
Resize
(
y
->
dims
());
auto
place
=
context
.
GetEigenDevice
<
Place
>
();
auto
place
=
context
.
GetEigenDevice
<
Place
>
();
size_t
element_len
=
framework
::
product
(
x_dims
)
/
x_dims
[
0
];
size_t
element_len
=
framework
::
product
(
x_dims
)
/
x_dims
[
0
];
T
*
out_data
=
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
out_data
=
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
@@ -57,6 +56,18 @@ class SeqExpandKernel : public framework::OpKernel<T> {
...
@@ -57,6 +56,18 @@ class SeqExpandKernel : public framework::OpKernel<T> {
}
}
};
};
/*
*Given Grad(Out)
*
* Grad(Out).lod = [[0, 2],
* [0, 3, 6]]
* Grad(Out).data = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
* Then
* Grad(X).data = [(0.1 + 0.2 + 0.3), (0.4 + 0.5 + 0.6)]
* = [0.6, 1.5]
* Grad(X).lod = Input(X).lod
*
* */
template
<
typename
Place
,
typename
T
>
template
<
typename
Place
,
typename
T
>
class
SeqExpandGradKernel
:
public
framework
::
OpKernel
<
T
>
{
class
SeqExpandGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
...
@@ -68,10 +79,8 @@ class SeqExpandGradKernel : public framework::OpKernel<T> {
...
@@ -68,10 +79,8 @@ class SeqExpandGradKernel : public framework::OpKernel<T> {
auto
out_last_level
=
out
->
lod
().
back
();
auto
out_last_level
=
out
->
lod
().
back
();
d_x
->
set_lod
(
x
->
lod
());
d_x
->
set_lod
(
x
->
lod
());
const
T
*
d_out_data
=
d_out
->
data
<
T
>
();
const
T
*
d_out_data
=
d_out
->
data
<
T
>
();
auto
d_out_dims
=
d_out
->
dims
();
T
*
d_x_data
=
d_x
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
d_x_data
=
d_x
->
mutable_data
<
T
>
(
context
.
GetPlace
());
size_t
element_len
=
framework
::
product
(
d_out_dims
)
/
d_out_dims
[
0
];
size_t
element_len
=
d_out
->
numel
()
/
d_out
->
dims
()[
0
];
for
(
size_t
i
=
0
;
i
<
out_last_level
.
size
()
-
1
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
out_last_level
.
size
()
-
1
;
++
i
)
{
size_t
repeat
=
out_last_level
[
i
+
1
]
-
out_last_level
[
i
];
size_t
repeat
=
out_last_level
[
i
+
1
]
-
out_last_level
[
i
];
Eigen
::
TensorMap
<
Eigen
::
TensorMap
<
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录