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

标签 tensorflow machine-learning keras deep-learning

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

相关文章:

python - Tensorflow:使用 tf.mat_fn() 或 tf.nn.dynamic_rnn() 在 LSTM 之前应用层有什么区别?

python-3.x - `return_sequences = False` 在 pytorch LSTM 中等效

c++ - Caffe中的CHECK & CHECK_EQ等类函数宏的定义具体在哪里?

python - 使用 Keras 和 TensorFlow 获取受众洞察

tensorflow - 获取 Tensorflow Serving 中暴露模型的信息

python - 将多个张量成对相乘 keras

machine-learning - 不使用开发集时的偏差

machine-learning - 如何在keras中将词嵌入和softmax权重结合起来?

tensorflow - 多标签二元分类中的 Keras class_weight

python - Keras:ResourceExhaustedError(请参阅上面的回溯):分配具有形状的张量时出现 OOM [26671,32,32,64]