Reputation: 183
I am trying to reproduce polynomial decay
for learning rate decay
in Keras
framework which as implemented in Tensorflow
framework is given below.
def poly_decay(step, initial_value, decay_period_images_seen):
"""
Decays a variable using a polynomial law.
:param step: number of images seen by the network since the beginning of the training.
:param initial_value: The initial value of the variable to decay..
:param decay_period_images_seen: the decay period in terms of images seen by the network
(1 epoch of 10 batches of 6 images each means that 1 epoch = 60 images seen).
Thus this value must be a multiple of the number of batches
:return: The decayed variable.
"""
factor = 1.0 - (tf.cast(step, tf.float32) / float(decay_period_images_seen))
lrate = initial_value * np.power(factor, 0.9)
return lrate
Does Keras offer any hidden parameter (which perhaps I don't know about) for global step
or is there an equivalent of global step
in Keras? Or is there any alternative way to implement polynomial learning rate decay
in Keras
framework ?
Upvotes: 2
Views: 1439
Reputation: 2047
Basically, the parameter is itself provided as arguments for optimisers
.
Take a look at optimizers.
sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='mean_squared_error', optimizer=sgd)
So here, you can just pass in the poly_decay()
as a parameter.
Usually we use time-based decay
instead of polynomial decay
:
learning_rate = 0.1
decay_rate = learning_rate / epochs
momentum = 0.8
sgd = SGD(lr=learning_rate, momentum=momentum, decay=decay_rate, nesterov=False)
Check this blog for more reference!!
Upvotes: 1