Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
2c5d4c6d
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看板
提交
2c5d4c6d
编写于
10月 30, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean code and update doc.
上级
1d7c03e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
11 addition
and
21 deletion
+11
-21
paddle/operators/lstm_op.cc
paddle/operators/lstm_op.cc
+5
-5
paddle/operators/lstm_op.h
paddle/operators/lstm_op.h
+1
-13
python/paddle/v2/framework/tests/test_lstm_op.py
python/paddle/v2/framework/tests/test_lstm_op.py
+5
-3
未找到文件。
paddle/operators/lstm_op.cc
浏览文件 @
2c5d4c6d
...
@@ -126,11 +126,11 @@ class LSTMOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -126,11 +126,11 @@ class LSTMOpMaker : public framework::OpProtoAndCheckerMaker {
" - Bias = {b_c, b_i, b_f, b_o, W_ic, W_fc, W_oc}."
)
" - Bias = {b_c, b_i, b_f, b_o, W_ic, W_fc, W_oc}."
)
.
AsDispensable
();
.
AsDispensable
();
AddOutput
(
"Hidden"
,
AddOutput
(
"Hidden"
,
"(LoDTensor) the hidden state
lod tensor
of LSTM operator. "
"(LoDTensor) the hidden state of LSTM operator. "
"The shape and lod is the same with the `Input`."
);
"The shape
is (T x D),
and lod is the same with the `Input`."
);
AddOutput
(
"Cell"
,
AddOutput
(
"Cell"
,
"(LoDTensor) the cell state
lod tensor
of LSTM operator. "
"(LoDTensor) the cell state of LSTM operator. "
"The shape and lod is the same with the `Input`."
);
"The shape
is (T x D),
and lod is the same with the `Input`."
);
AddOutput
(
"BatchGate"
,
AddOutput
(
"BatchGate"
,
"(LoDTensor) This LoDTensor contains input gate, forget gate "
"(LoDTensor) This LoDTensor contains input gate, forget gate "
"and output gate after the nonlinear computation. This "
"and output gate after the nonlinear computation. This "
...
@@ -141,7 +141,7 @@ class LSTMOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -141,7 +141,7 @@ class LSTMOpMaker : public framework::OpProtoAndCheckerMaker {
"in the raw input."
)
"in the raw input."
)
.
AsIntermediate
();
.
AsIntermediate
();
AddOutput
(
"BatchCellPreAct"
,
AddOutput
(
"BatchCellPreAct"
,
"(LoDTensor) This LoDTensor is g
e
t in the forward and used "
"(LoDTensor) This LoDTensor is g
o
t in the forward and used "
"in the backward."
)
"in the backward."
)
.
AsIntermediate
();
.
AsIntermediate
();
AddAttr
<
bool
>
(
"usePeepholes"
,
AddAttr
<
bool
>
(
"usePeepholes"
,
...
...
paddle/operators/lstm_op.h
浏览文件 @
2c5d4c6d
...
@@ -155,7 +155,6 @@ class LSTMGradKernel : public framework::OpKernel<T> {
...
@@ -155,7 +155,6 @@ class LSTMGradKernel : public framework::OpKernel<T> {
auto
*
batch_cell_pre_act
=
ctx
.
Input
<
LoDTensor
>
(
"BatchCellPreAct"
);
auto
*
batch_cell_pre_act
=
ctx
.
Input
<
LoDTensor
>
(
"BatchCellPreAct"
);
auto
*
hidden_g
=
ctx
.
Input
<
LoDTensor
>
(
framework
::
GradVarName
(
"Hidden"
));
auto
*
hidden_g
=
ctx
.
Input
<
LoDTensor
>
(
framework
::
GradVarName
(
"Hidden"
));
// auto* cell_g = ctx.Input<LoDTensor>(framework::GradVarName("Cell"));
auto
*
in_g
=
ctx
.
Output
<
LoDTensor
>
(
framework
::
GradVarName
(
"Input"
));
auto
*
in_g
=
ctx
.
Output
<
LoDTensor
>
(
framework
::
GradVarName
(
"Input"
));
auto
*
weight_g
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Weight"
));
auto
*
weight_g
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Weight"
));
...
@@ -251,7 +250,7 @@ class LSTMGradKernel : public framework::OpKernel<T> {
...
@@ -251,7 +250,7 @@ class LSTMGradKernel : public framework::OpKernel<T> {
lstm_grad
.
gateGrad
=
gate_g
.
data
<
T
>
();
lstm_grad
.
gateGrad
=
gate_g
.
data
<
T
>
();
lstm_grad
.
outputGrad
=
out_g
.
data
<
T
>
();
lstm_grad
.
outputGrad
=
out_g
.
data
<
T
>
();
if
(
n
!=
0
)
{
if
(
n
)
{
int
bstart_pre
=
static_cast
<
int
>
(
batch_starts
[
n
-
1
]);
int
bstart_pre
=
static_cast
<
int
>
(
batch_starts
[
n
-
1
]);
Tensor
cell_pre
=
batch_cell
.
Slice
(
bstart_pre
,
bstart
);
Tensor
cell_pre
=
batch_cell
.
Slice
(
bstart_pre
,
bstart
);
Tensor
cell_pre_g
=
batch_cell_g
.
Slice
(
bstart_pre
,
bstart
);
Tensor
cell_pre_g
=
batch_cell_g
.
Slice
(
bstart_pre
,
bstart
);
...
@@ -292,17 +291,6 @@ class LSTMGradKernel : public framework::OpKernel<T> {
...
@@ -292,17 +291,6 @@ class LSTMGradKernel : public framework::OpKernel<T> {
}
}
if
(
bias
&&
bias_g
)
{
if
(
bias
&&
bias_g
)
{
/* backward bias */
/* backward bias */
// Following Eigen computation failed for double type on GPU device.
// bias_g->mutable_data<T>(ctx.GetPlace());
// Tensor bias_mat;
// bias_mat.ShareDataWith(*bias_g);
// bias_mat.Resize({1, 4 * frame_size});
// auto bias_g_e = EigenVector<T>::Flatten(bias_mat);
// auto gate_g_e = EigenMatrix<T>::From(batch_gate_g);
// Eigen::array<int, 1> dims{{0}};
// bias_g_e.device(ctx.GetEigenDevice<Place>()) = gate_g_e.sum(dims);
int
m
=
static_cast
<
int
>
(
batch_gate_g
.
dims
()[
0
]);
int
m
=
static_cast
<
int
>
(
batch_gate_g
.
dims
()[
0
]);
int
n
=
static_cast
<
int
>
(
batch_gate_g
.
dims
()[
1
]);
int
n
=
static_cast
<
int
>
(
batch_gate_g
.
dims
()[
1
]);
...
...
python/paddle/v2/framework/tests/test_lstm_op.py
浏览文件 @
2c5d4c6d
...
@@ -161,9 +161,11 @@ class TestLstmOp(OpTest):
...
@@ -161,9 +161,11 @@ class TestLstmOp(OpTest):
#TODO(qingqing) add more unit testing case
#TODO(qingqing) add more unit testing case
def
test_check_grad
(
self
):
def
test_check_grad
(
self
):
# TODO(qingqing) remove folowing two lines after the check_grad is refined.
# TODO(qingqing) remove folowing lines after the check_grad is refined.
self
.
outputs
[
'BatchGate'
]
=
None
N
=
len
(
self
.
lod
[
0
])
-
1
self
.
outputs
[
'BatchCellPreAct'
]
=
None
self
.
outputs
[
'BatchGate'
]
=
np
.
zeros
((
N
,
4
*
self
.
D
)).
astype
(
'float64'
)
self
.
outputs
[
'BatchCellPreAct'
]
=
np
.
zeros
(
(
N
,
self
.
D
)).
astype
(
'float64'
)
self
.
check_grad
(
self
.
check_grad
(
[
'Input'
,
'Weight'
,
'Bias'
],
[
'Hidden'
],
max_relative_error
=
0.02
)
[
'Input'
,
'Weight'
,
'Bias'
],
[
'Hidden'
],
max_relative_error
=
0.02
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录