我正在尝试在Keras
框架中重现学习率衰减
的多项式衰减
,该框架在Tensorflow
中实现框架如下。
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
Keras 是否为全局步骤
提供任何隐藏参数(也许我不知道),或者 Keras 中是否存在与全局步骤
等效的参数?或者是否有其他方法可以在 Keras
框架中实现多项式学习率衰减
?
最佳答案
基本上,参数本身作为优化器
的参数提供。
看看optimizers .
sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='mean_squared_error', optimizer=sgd)
所以在这里,您只需传入 poly_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)
检查这个blog更多引用!!
关于tensorflow - 有没有办法在Keras框架中使用global_step?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56711938/