Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
de3e2e7c
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
de3e2e7c
编写于
12月 29, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
12月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add CyclicalCosineDecay (#1599)
上级
8985f6c2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
98 addition
and
6 deletion
+98
-6
ppocr/optimizer/learning_rate.py
ppocr/optimizer/learning_rate.py
+47
-4
ppocr/optimizer/lr_scheduler.py
ppocr/optimizer/lr_scheduler.py
+49
-0
tools/program.py
tools/program.py
+2
-2
未找到文件。
ppocr/optimizer/learning_rate.py
浏览文件 @
de3e2e7c
...
...
@@ -18,6 +18,7 @@ from __future__ import print_function
from
__future__
import
unicode_literals
from
paddle.optimizer
import
lr
from
.lr_scheduler
import
CyclicalCosineDecay
class
Linear
(
object
):
...
...
@@ -46,7 +47,7 @@ class Linear(object):
self
.
end_lr
=
end_lr
self
.
power
=
power
self
.
last_epoch
=
last_epoch
self
.
warmup_epoch
=
warmup_epoch
*
step_each_epoch
self
.
warmup_epoch
=
round
(
warmup_epoch
*
step_each_epoch
)
def
__call__
(
self
):
learning_rate
=
lr
.
PolynomialDecay
(
...
...
@@ -87,7 +88,7 @@ class Cosine(object):
self
.
learning_rate
=
learning_rate
self
.
T_max
=
step_each_epoch
*
epochs
self
.
last_epoch
=
last_epoch
self
.
warmup_epoch
=
warmup_epoch
*
step_each_epoch
self
.
warmup_epoch
=
round
(
warmup_epoch
*
step_each_epoch
)
def
__call__
(
self
):
learning_rate
=
lr
.
CosineAnnealingDecay
(
...
...
@@ -129,7 +130,7 @@ class Step(object):
self
.
learning_rate
=
learning_rate
self
.
gamma
=
gamma
self
.
last_epoch
=
last_epoch
self
.
warmup_epoch
=
warmup_epoch
*
step_each_epoch
self
.
warmup_epoch
=
round
(
warmup_epoch
*
step_each_epoch
)
def
__call__
(
self
):
learning_rate
=
lr
.
StepDecay
(
...
...
@@ -168,7 +169,7 @@ class Piecewise(object):
self
.
boundaries
=
[
step_each_epoch
*
e
for
e
in
decay_epochs
]
self
.
values
=
values
self
.
last_epoch
=
last_epoch
self
.
warmup_epoch
=
warmup_epoch
*
step_each_epoch
self
.
warmup_epoch
=
round
(
warmup_epoch
*
step_each_epoch
)
def
__call__
(
self
):
learning_rate
=
lr
.
PiecewiseDecay
(
...
...
@@ -183,3 +184,45 @@ class Piecewise(object):
end_lr
=
self
.
values
[
0
],
last_epoch
=
self
.
last_epoch
)
return
learning_rate
class
CyclicalCosine
(
object
):
"""
Cyclical cosine learning rate decay
Args:
learning_rate(float): initial learning rate
step_each_epoch(int): steps each epoch
epochs(int): total training epochs
cycle(int): period of the cosine learning rate
last_epoch (int, optional): The index of last epoch. Can be set to restart training. Default: -1, means initial learning rate.
"""
def
__init__
(
self
,
learning_rate
,
step_each_epoch
,
epochs
,
cycle
,
warmup_epoch
=
0
,
last_epoch
=-
1
,
**
kwargs
):
super
(
CyclicalCosine
,
self
).
__init__
()
self
.
learning_rate
=
learning_rate
self
.
T_max
=
step_each_epoch
*
epochs
self
.
last_epoch
=
last_epoch
self
.
warmup_epoch
=
round
(
warmup_epoch
*
step_each_epoch
)
self
.
cycle
=
round
(
cycle
*
step_each_epoch
)
def
__call__
(
self
):
learning_rate
=
CyclicalCosineDecay
(
learning_rate
=
self
.
learning_rate
,
T_max
=
self
.
T_max
,
cycle
=
self
.
cycle
,
last_epoch
=
self
.
last_epoch
)
if
self
.
warmup_epoch
>
0
:
learning_rate
=
lr
.
LinearWarmup
(
learning_rate
=
learning_rate
,
warmup_steps
=
self
.
warmup_epoch
,
start_lr
=
0.0
,
end_lr
=
self
.
learning_rate
,
last_epoch
=
self
.
last_epoch
)
return
learning_rate
ppocr/optimizer/lr_scheduler.py
0 → 100644
浏览文件 @
de3e2e7c
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
paddle.optimizer.lr
import
LRScheduler
class
CyclicalCosineDecay
(
LRScheduler
):
def
__init__
(
self
,
learning_rate
,
T_max
,
cycle
=
1
,
last_epoch
=-
1
,
eta_min
=
0.0
,
verbose
=
False
):
"""
Cyclical cosine learning rate decay
A learning rate which can be referred in https://arxiv.org/pdf/2012.12645.pdf
Args:
learning rate(float): learning rate
T_max(int): maximum epoch num
cycle(int): period of the cosine decay
last_epoch (int, optional): The index of last epoch. Can be set to restart training. Default: -1, means initial learning rate.
eta_min(float): minimum learning rate during training
verbose(bool): whether to print learning rate for each epoch
"""
super
(
CyclicalCosineDecay
,
self
).
__init__
(
learning_rate
,
last_epoch
,
verbose
)
self
.
cycle
=
cycle
self
.
eta_min
=
eta_min
def
get_lr
(
self
):
if
self
.
last_epoch
==
0
:
return
self
.
base_lr
reletive_epoch
=
self
.
last_epoch
%
self
.
cycle
lr
=
self
.
eta_min
+
0.5
*
(
self
.
base_lr
-
self
.
eta_min
)
*
\
(
1
+
math
.
cos
(
math
.
pi
*
reletive_epoch
/
self
.
cycle
))
return
lr
tools/program.py
浏览文件 @
de3e2e7c
...
...
@@ -179,9 +179,9 @@ def train(config,
if
'start_epoch'
in
best_model_dict
:
start_epoch
=
best_model_dict
[
'start_epoch'
]
else
:
start_epoch
=
0
start_epoch
=
1
for
epoch
in
range
(
start_epoch
,
epoch_num
):
for
epoch
in
range
(
start_epoch
,
epoch_num
+
1
):
if
epoch
>
0
:
train_dataloader
=
build_dataloader
(
config
,
'Train'
,
device
,
logger
)
train_batch_cost
=
0.0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录