-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adderd learning rate scheduler in training
- Loading branch information
Showing
2 changed files
with
25 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def poly_lr_scheduler(optimizer, init_lr, iter, lr_decay_iter=1, max_iter=30000, power=0.9,): | ||
"""Polynomial decay of learning rate | ||
:param init_lr is base learning rate | ||
:param iter is a current iteration | ||
:param lr_decay_iter how frequently decay occurs, default is 1 | ||
:param max_iter is number of maximum iterations | ||
:param power is a polymomial power | ||
""" | ||
if iter % lr_decay_iter or iter > max_iter: | ||
return optimizer | ||
|
||
for param_group in optimizer.param_groups: | ||
param_group['lr'] = init_lr*(1 - iter/max_iter)**power | ||
|
||
|
||
def adjust_learning_rate(optimizer, init_lr, epoch): | ||
"""Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" | ||
lr = init_lr * (0.1 ** (epoch // 30)) | ||
for param_group in optimizer.param_groups: | ||
param_group['lr'] = lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters