gpt4 book ai didi

tensorflow - 有没有办法在Keras框架中使用global_step?

转载 作者:行者123 更新时间:2023-11-30 09:15:37 27 4
gpt4 key购买 nike

我正在尝试在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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com