Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
ccb7ca30
Commit
ccb7ca30
authored
Feb 16, 2019
by
wangg12
Browse files
add cosine lr schedule
parent
c8c34938
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
mmcv/runner/hooks/lr_updater.py
mmcv/runner/hooks/lr_updater.py
+19
-0
No files found.
mmcv/runner/hooks/lr_updater.py
View file @
ccb7ca30
from
__future__
import
division
from
__future__
import
division
from
math
import
cos
,
pi
from
.hook
import
Hook
from
.hook
import
Hook
...
@@ -161,3 +163,20 @@ class InvLrUpdaterHook(LrUpdaterHook):
...
@@ -161,3 +163,20 @@ class InvLrUpdaterHook(LrUpdaterHook):
def
get_lr
(
self
,
runner
,
base_lr
):
def
get_lr
(
self
,
runner
,
base_lr
):
progress
=
runner
.
epoch
if
self
.
by_epoch
else
runner
.
iter
progress
=
runner
.
epoch
if
self
.
by_epoch
else
runner
.
iter
return
base_lr
*
(
1
+
self
.
gamma
*
progress
)
**
(
-
self
.
power
)
return
base_lr
*
(
1
+
self
.
gamma
*
progress
)
**
(
-
self
.
power
)
class
CosineLrUpdaterHook
(
LrUpdaterHook
):
def
__init__
(
self
,
target_lr
=
0
,
**
kwargs
):
self
.
target_lr
=
target_lr
super
(
CosineLrUpdaterHook
,
self
).
__init__
(
**
kwargs
)
def
get_lr
(
self
,
runner
,
base_lr
):
if
self
.
by_epoch
:
progress
=
runner
.
epoch
max_progress
=
runner
.
max_epochs
else
:
progress
=
runner
.
iter
max_progress
=
runner
.
max_iters
return
self
.
target_lr
+
0.5
*
(
base_lr
-
self
.
target_lr
)
*
\
(
1
+
cos
(
pi
*
(
progress
/
max_progress
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment