allow optimizers to adjust their own learning rate
This commit is contained in:
parent
22dc651cce
commit
1b1184480a
2 changed files with 9 additions and 6 deletions
|
@ -314,9 +314,8 @@ class RMSprop(Optimizer):
|
||||||
class Adam(Optimizer):
|
class Adam(Optimizer):
|
||||||
# paper: https://arxiv.org/abs/1412.6980
|
# paper: https://arxiv.org/abs/1412.6980
|
||||||
# Adam generalizes* RMSprop, and
|
# Adam generalizes* RMSprop, and
|
||||||
# adds a decay term to the regular (non-squared) delta, and
|
# adds a decay term to the regular (non-squared) delta, and performs
|
||||||
# does some decay-gain voodoo. (i guess it's compensating
|
# debiasing to compensate for the filtered deltas starting from zero.
|
||||||
# for the filtered deltas starting from zero)
|
|
||||||
|
|
||||||
# * Adam == RMSprop when
|
# * Adam == RMSprop when
|
||||||
# Adam.b1 == 0
|
# Adam.b1 == 0
|
||||||
|
@ -1072,7 +1071,7 @@ class Learner:
|
||||||
def __init__(self, optim, epochs=100, rate=None):
|
def __init__(self, optim, epochs=100, rate=None):
|
||||||
assert isinstance(optim, Optimizer)
|
assert isinstance(optim, Optimizer)
|
||||||
self.optim = optim
|
self.optim = optim
|
||||||
self.start_rate = optim.alpha if rate is None else _f(rate)
|
self.start_rate = rate # None is okay; it'll use optim.alpha instead.
|
||||||
self.epochs = int(epochs)
|
self.epochs = int(epochs)
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
@ -1101,6 +1100,8 @@ class Learner:
|
||||||
self.optim.alpha = new_rate
|
self.optim.alpha = new_rate
|
||||||
|
|
||||||
def rate_at(self, epoch):
|
def rate_at(self, epoch):
|
||||||
|
if self.start_rate is None:
|
||||||
|
return self.optim.alpha
|
||||||
return self.start_rate
|
return self.start_rate
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
|
|
|
@ -136,10 +136,12 @@ if learner_class == SGDR:
|
||||||
learner = learner_class(optim, epochs=epochs//starts, rate=lr,
|
learner = learner_class(optim, epochs=epochs//starts, rate=lr,
|
||||||
restarts=starts-1, restart_decay=restart_decay,
|
restarts=starts-1, restart_decay=restart_decay,
|
||||||
expando=lambda i:0)
|
expando=lambda i:0)
|
||||||
else:
|
elif learner_class in (TriangularCLR, SineCLR, WaveCLR):
|
||||||
assert learner_class in (TriangularCLR, SineCLR, WaveCLR)
|
|
||||||
learner = learner_class(optim, epochs=epochs, lower_rate=0, upper_rate=lr,
|
learner = learner_class(optim, epochs=epochs, lower_rate=0, upper_rate=lr,
|
||||||
frequency=epochs//starts)
|
frequency=epochs//starts)
|
||||||
|
else:
|
||||||
|
lament('NOTE: no learning rate schedule selected.')
|
||||||
|
learner = Learner(optim, epochs=epochs)
|
||||||
|
|
||||||
loss = CategoricalCrossentropy()
|
loss = CategoricalCrossentropy()
|
||||||
mloss = Accuracy()
|
mloss = Accuracy()
|
||||||
|
|
Loading…
Reference in a new issue