Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
0a3825c5
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0a3825c5
编写于
8月 30, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support warmup for cosine and expo decay
上级
ffff9080
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
24 addition
and
55 deletion
+24
-55
ppcls/optimizer/learning_rate.py
ppcls/optimizer/learning_rate.py
+24
-55
未找到文件。
ppcls/optimizer/learning_rate.py
浏览文件 @
0a3825c5
...
...
@@ -112,35 +112,19 @@ class CosineWarmup(object):
self
.
lr
=
lr
self
.
step_each_epoch
=
step_each_epoch
self
.
epochs
=
epochs
self
.
warmup_epoch
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
float
(
warmup_epoch
),
dtype
=
'float32'
,
force_cpu
=
True
)
self
.
warmup_epoch
=
warmup_epoch
def
__call__
(
self
):
global_step
=
_decay_step_counter
()
learning_rate
=
fluid
.
layers
.
tensor
.
create_global_var
(
shape
=
[
1
],
value
=
0.0
,
dtype
=
'float32'
,
persistable
=
True
,
name
=
"learning_rate"
)
epoch
=
ops
.
floor
(
global_step
/
self
.
step_each_epoch
)
with
fluid
.
layers
.
control_flow
.
Switch
()
as
switch
:
with
switch
.
case
(
epoch
<
self
.
warmup_epoch
):
decayed_lr
=
self
.
lr
*
\
(
global_step
/
(
self
.
step_each_epoch
*
self
.
warmup_epoch
))
fluid
.
layers
.
tensor
.
assign
(
input
=
decayed_lr
,
output
=
learning_rate
)
with
switch
.
default
():
current_step
=
global_step
-
self
.
warmup_epoch
*
self
.
step_each_epoch
total_step
=
(
self
.
epochs
-
self
.
warmup_epoch
)
*
self
.
step_each_epoch
decayed_lr
=
self
.
lr
*
\
(
ops
.
cos
(
current_step
*
math
.
pi
/
total_step
)
+
1
)
/
2
fluid
.
layers
.
tensor
.
assign
(
input
=
decayed_lr
,
output
=
learning_rate
)
learning_rate
=
fluid
.
layers
.
cosine_decay
(
learning_rate
=
self
.
lr
,
step_each_epoch
=
self
.
step_each_epoch
,
epochs
=
self
.
epochs
)
learning_rate
=
fluid
.
layers
.
linear_lr_warmup
(
learning_rate
,
warmup_steps
=
self
.
warmup_epoch
*
self
.
step_each_epoch
,
start_lr
=
0.0
,
end_lr
=
self
.
lr
)
return
learning_rate
...
...
@@ -169,37 +153,22 @@ class ExponentialWarmup(object):
super
(
ExponentialWarmup
,
self
).
__init__
()
self
.
lr
=
lr
self
.
step_each_epoch
=
step_each_epoch
self
.
decay_epochs
=
decay_epochs
*
self
.
step_each_epoch
self
.
decay_epochs
=
decay_epochs
self
.
decay_rate
=
decay_rate
self
.
warmup_epoch
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
float
(
warmup_epoch
),
dtype
=
'float32'
,
force_cpu
=
True
)
self
.
warmup_epoch
=
warmup_epoch
def
__call__
(
self
):
global_step
=
_decay_step_counter
()
learning_rate
=
fluid
.
layers
.
tensor
.
create_global_var
(
shape
=
[
1
],
value
=
0.0
,
dtype
=
'float32'
,
persistable
=
True
,
name
=
"learning_rate"
)
epoch
=
ops
.
floor
(
global_step
/
self
.
step_each_epoch
)
with
fluid
.
layers
.
control_flow
.
Switch
()
as
switch
:
with
switch
.
case
(
epoch
<
self
.
warmup_epoch
):
decayed_lr
=
self
.
lr
*
\
(
global_step
/
(
self
.
step_each_epoch
*
self
.
warmup_epoch
))
fluid
.
layers
.
tensor
.
assign
(
input
=
decayed_lr
,
output
=
learning_rate
)
with
switch
.
default
():
rest_step
=
global_step
-
self
.
warmup_epoch
*
self
.
step_each_epoch
div_res
=
ops
.
floor
(
rest_step
/
self
.
decay_epochs
)
decayed_lr
=
self
.
lr
*
(
self
.
decay_rate
**
div_res
)
fluid
.
layers
.
tensor
.
assign
(
input
=
decayed_lr
,
output
=
learning_rate
)
learning_rate
=
fluid
.
layers
.
exponential_decay
(
learning_rate
=
self
.
lr
,
decay_steps
=
self
.
decay_epochs
*
self
.
step_each_epoch
,
decay_rate
=
self
.
decay_rate
,
staircase
=
False
)
learning_rate
=
fluid
.
layers
.
linear_lr_warmup
(
learning_rate
,
warmup_steps
=
self
.
warmup_epoch
*
self
.
step_each_epoch
,
start_lr
=
0.0
,
end_lr
=
self
.
lr
)
return
learning_rate
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录