Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
916f42bc
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看板
提交
916f42bc
编写于
9月 11, 2018
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine fusion gru infershape
上级
a5556d44
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
16 deletion
+49
-16
paddle/fluid/operators/fusion_gru_op.cc
paddle/fluid/operators/fusion_gru_op.cc
+49
-16
未找到文件。
paddle/fluid/operators/fusion_gru_op.cc
浏览文件 @
916f42bc
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/fluid/operators/fusion_gru_op.h"
#include <cstring> // for memcpy
#include <string>
#include "paddle/fluid/framework/shape_runtime_infer.h"
#include "paddle/fluid/operators/math/blas.h"
#include "paddle/fluid/operators/math/cpu_vec.h"
#include "paddle/fluid/operators/math/fc_compute.h"
...
...
@@ -25,14 +26,46 @@ namespace paddle {
namespace
operators
{
void
FusionGRUOp
::
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of GRU should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"WeightX"
),
"Input(WeightX) of GRU should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"WeightH"
),
"Input(WeightH) of GRU should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"XX"
),
"Output(XX) of GRU should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Hidden"
),
"Output(Hidden) of GRU should not be null."
);
auto
*
runtime_ctx
=
dynamic_cast
<
framework
::
RuntimeInferShapeContext
*>
(
ctx
);
if
(
runtime_ctx
==
nullptr
)
{
LOG
(
FATAL
)
<<
"Should have runtime infer context"
;
}
const
auto
&
ins
=
runtime_ctx
->
OpBase
().
Inputs
();
const
auto
&
outs
=
runtime_ctx
->
OpBase
().
Outputs
();
const
auto
&
scope
=
runtime_ctx
->
InferScope
();
const
auto
ins_end
=
ins
.
end
();
const
auto
outs_end
=
outs
.
end
();
auto
fair_input
=
[
&
](
const
std
::
string
&
name
)
->
bool
{
auto
it
=
ins
.
find
(
name
);
if
(
it
==
ins_end
)
{
return
false
;
}
const
auto
&
in
=
it
->
second
;
if
(
in
.
size
()
!=
1
||
in
[
0
]
==
framework
::
kEmptyVarName
)
{
return
false
;
}
return
scope
.
FindVar
(
in
[
0
])
!=
nullptr
;
};
auto
fair_output
=
[
&
](
const
std
::
string
&
name
)
->
bool
{
auto
it
=
outs
.
find
(
name
);
if
(
it
==
outs_end
)
{
return
false
;
}
const
auto
&
out
=
it
->
second
;
if
(
out
.
size
()
!=
1
||
out
[
0
]
==
framework
::
kEmptyVarName
)
{
return
false
;
}
return
scope
.
FindVar
(
out
[
0
])
!=
nullptr
;
};
PADDLE_ENFORCE
(
fair_input
(
"X"
),
"Assert only one Input(X) of GRU."
);
PADDLE_ENFORCE
(
fair_input
(
"WeightX"
),
"Assert only one Input(WeightX) of GRU."
);
PADDLE_ENFORCE
(
fair_input
(
"WeightH"
),
"Assert only one Input(WeightH) of GRU."
);
PADDLE_ENFORCE
(
fair_output
(
"XX"
),
"Assert only one Output(XX) of GRU."
);
PADDLE_ENFORCE
(
fair_output
(
"Hidden"
),
"Assert only one Output(Hidden) of GRU."
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
PADDLE_ENFORCE_EQ
(
x_dims
.
size
(),
2
,
"Input(X)'s rank must be 2."
);
...
...
@@ -58,12 +91,12 @@ void FusionGRUOp::InferShape(framework::InferShapeContext* ctx) const {
"should be 3 * %d."
,
frame_size
);
if
(
ctx
->
HasI
nput
(
"H0"
))
{
if
(
fair_i
nput
(
"H0"
))
{
auto
h0_dims
=
ctx
->
GetInputDim
(
"H0"
);
PADDLE_ENFORCE_EQ
(
h0_dims
[
1
],
frame_size
,
"The width of H0 must be equal to frame_size."
);
}
if
(
ctx
->
HasI
nput
(
"Bias"
))
{
if
(
fair_i
nput
(
"Bias"
))
{
auto
b_dims
=
ctx
->
GetInputDim
(
"Bias"
);
PADDLE_ENFORCE_EQ
(
b_dims
.
size
(),
2
,
"The rank of Input(Bias) should be 2."
);
PADDLE_ENFORCE_EQ
(
b_dims
[
0
],
1
,
...
...
@@ -79,12 +112,12 @@ void FusionGRUOp::InferShape(framework::InferShapeContext* ctx) const {
xx_width
=
wx_dims
[
1
];
}
else
{
xx_width
=
x_dims
[
1
]
>
wx_dims
[
1
]
?
wx_dims
[
1
]
:
x_dims
[
1
];
PADDLE_ENFORCE
(
ctx
->
HasO
utput
(
"ReorderedH0"
),
"
Output(ReorderedH0) of GRU should not be null
."
);
PADDLE_ENFORCE
(
ctx
->
HasO
utput
(
"BatchedInput"
),
"
Output(BatchedInput) of GRU should not be null
."
);
PADDLE_ENFORCE
(
ctx
->
HasO
utput
(
"BatchedOut"
),
"
Output(BatchedOut) of GRU should not be null
."
);
PADDLE_ENFORCE
(
fair_o
utput
(
"ReorderedH0"
),
"
Assert only one Output(ReorderedH0) of GRU
."
);
PADDLE_ENFORCE
(
fair_o
utput
(
"BatchedInput"
),
"
Assert only one Output(BatchedInput) of GRU
."
);
PADDLE_ENFORCE
(
fair_o
utput
(
"BatchedOut"
),
"
Assert only one Output(BatchedOut) of GRU
."
);
ctx
->
SetOutputDim
(
"BatchedInput"
,
{
x_dims
[
0
],
wx_dims
[
1
]});
ctx
->
SetOutputDim
(
"BatchedOut"
,
out_dims
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录