Skip to content

Instantly share code, notes, and snippets.

@avijit9
Forked from Deepayan137/stlr.py
Created February 17, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avijit9/47d57471abec0e6b0cfa8429e86fd171 to your computer and use it in GitHub Desktop.
Save avijit9/47d57471abec0e6b0cfa8429e86fd171 to your computer and use it in GitHub Desktop.
'STLR scheduler from https://arxiv.org/abs/1801.06146'
class STLR(_LRScheduler):
def __init__(self, optimizer, T_max, last_epoch=-1, ratio=32):
self.T_max = T_max
self.cut = np.floor(T_max*0.1)
self.ratio = ratio
super(STLR, self).__init__(optimizer, last_epoch)
def get_lr(self):
if self.last_epoch < self.cut:
p = self.last_epoch/self.cut
else:
fraction = (self.last_epoch - self.cut)/(self.cut*(1/self.ratio - 1))
p = 1 - fraction
return [base_lr*(1 + p*(self.ratio - 1))/self.ratio for base_lr in self.base_lrs]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment