Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
c10da26c
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c10da26c
编写于
10月 05, 2017
作者:
S
sidgoyal78
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify implementation
上级
d28b3094
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
28 addition
and
23 deletion
+28
-23
paddle/operators/momentum_op.cc
paddle/operators/momentum_op.cc
+20
-15
paddle/operators/momentum_op.h
paddle/operators/momentum_op.h
+6
-6
python/paddle/v2/framework/tests/test_momentum_op.py
python/paddle/v2/framework/tests/test_momentum_op.py
+2
-2
未找到文件。
paddle/operators/momentum_op.cc
浏览文件 @
c10da26c
...
@@ -57,25 +57,30 @@ class MomentumOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -57,25 +57,30 @@ class MomentumOpMaker : public framework::OpProtoAndCheckerMaker {
MomentumOpMaker
(
framework
::
OpProto
*
proto
,
MomentumOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Param"
,
"Input parameter"
);
AddInput
(
"Param"
,
AddInput
(
"Grad"
,
"Input gradient"
);
"(Tensor, default Tensor<float>) "
AddInput
(
"Velocity"
,
"Input velocity"
);
"Input parameter that has to be updated"
);
AddInput
(
"LearningRate"
,
"Input learning rate"
);
AddInput
(
"Grad"
,
"(Tensor, default Tensor<float>) "
AddOutput
(
"ParamOut"
,
"Output parameter"
);
"Input gradient of the parameter"
);
AddOutput
(
"VelocityOut"
,
"Output velocity"
);
AddInput
(
"Velocity"
,
"(Tensor, default Tensor<float>) "
AddAttr
<
float
>
(
"mu"
,
"Momentum coefficient"
);
"Input velocity (corresponding to the parameter) "
"that has to be updated"
);
AddInput
(
"LearningRate"
,
"(Tensor, default Tensor<float>) "
"Input learning rate"
);
AddOutput
(
"ParamOut"
,
"(Tensor) Output updated parameter"
);
AddOutput
(
"VelocityOut"
,
"(Tensor) Output updated velocity"
);
AddAttr
<
float
>
(
"mu"
,
"(float) Momentum coefficient"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Momentum Algorithm (momentum).
Momentum Algorithm (momentum).
velocity_out = mu * velocity - learning_rate * grad
velocity = mu * velocity + gradient
param_out = param + velocity_out
param = param - learning_rate * velocity
Ref: Sutskever, Ilya, et al. "On the importance of initialization
and momentum in deep learning." ICML 2013;
http://jmlr.org/proceedings/papers/v28/sutskever13.pdf
)DOC"
);
)DOC"
);
}
}
...
...
paddle/operators/momentum_op.h
浏览文件 @
c10da26c
...
@@ -36,16 +36,16 @@ class MomentumOpKernel : public framework::OpKernel<T> {
...
@@ -36,16 +36,16 @@ class MomentumOpKernel : public framework::OpKernel<T> {
float
mu
=
ctx
.
Attr
<
float
>
(
"mu"
);
float
mu
=
ctx
.
Attr
<
float
>
(
"mu"
);
auto
p
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Param"
));
auto
p
aram
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Param"
));
auto
g
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Grad"
));
auto
g
rad
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Grad"
));
auto
v
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Velocity"
));
auto
v
elocity
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Velocity"
));
float
l
r
=
ctx
.
Input
<
Tensor
>
(
"LearningRate"
)
->
data
<
float
>
()[
0
];
float
l
earning_rate
=
ctx
.
Input
<
Tensor
>
(
"LearningRate"
)
->
data
<
float
>
()[
0
];
auto
p_out
=
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
p_out
=
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
v_out
=
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
v_out
=
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
place
=
ctx
.
GetEigenDevice
<
Place
>
();
auto
place
=
ctx
.
GetEigenDevice
<
Place
>
();
v_out
.
device
(
place
)
=
mu
*
v
-
lr
*
g
;
v_out
.
device
(
place
)
=
velocity
*
mu
+
grad
;
p_out
.
device
(
place
)
=
p
+
v_out
;
p_out
.
device
(
place
)
=
p
aram
-
learning_rate
*
v_out
;
}
}
};
};
...
...
python/paddle/v2/framework/tests/test_momentum_op.py
浏览文件 @
c10da26c
...
@@ -22,8 +22,8 @@ class TestMomentumOp(OpTest):
...
@@ -22,8 +22,8 @@ class TestMomentumOp(OpTest):
self
.
attrs
=
{
'mu'
:
mu
}
self
.
attrs
=
{
'mu'
:
mu
}
velocity_out
=
mu
*
velocity
-
learning_rate
*
grad
velocity_out
=
mu
*
velocity
+
grad
param_out
=
param
+
velocity_out
param_out
=
param
-
learning_rate
*
velocity_out
self
.
outputs
=
{
'ParamOut'
:
param_out
,
'VelocityOut'
:
velocity_out
}
self
.
outputs
=
{
'ParamOut'
:
param_out
,
'VelocityOut'
:
velocity_out
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录