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
1d6e91b1
Unverified
Commit
1d6e91b1
authored
Mar 01, 2019
by
Kai Chen
Committed by
GitHub
Mar 01, 2019
Browse files
Merge pull request #35 from wangg12/master
add cosine lr schedule
parents
c8c34938
ccb7ca30
Changes
1
Show 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 @
1d6e91b1
from
__future__
import
division
from
math
import
cos
,
pi
from
.hook
import
Hook
...
...
@@ -161,3 +163,20 @@ class InvLrUpdaterHook(LrUpdaterHook):
def
get_lr
(
self
,
runner
,
base_lr
):
progress
=
runner
.
epoch
if
self
.
by_epoch
else
runner
.
iter
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