【问题标题】:Exponential decay learning rate parameters of Adam optimizer in KerasKeras中Adam优化器的指数衰减学习率参数
【发布时间】:2021-09-25 15:29:44
【问题描述】:

考虑以下信息:

  • 初始学习率:0.0002

  • 衰减系数:0.7

  • ephocs:70

我的问题是选择衰减步骤,使衰减每两个时期发生一次。如何在 Keras 中解决此问题?

这是指数衰减学习率的公式:

click here to view the image

【问题讨论】:

    标签: tensorflow machine-learning keras tf.keras


    【解决方案1】:

    似乎可以使用ExponentialDecay LearningRateScheduler。要每两个时期衰减一次,decay_steps 应该是num_steps_per_epoch * 2。还提供staircase 参数为True,以便学习率离散衰减。

    类似这样的东西(我没有运行这段代码):

    initial_learning_rate = 0.0002
    steps_per_epoch = ...
    lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(
        initial_learning_rate,
        decay_steps=steps_per_epoch * 2,
        decay_rate=0.7,
        staircase=True)
    

    然后使用learning_rate 参数将lr_schedule 传递给Adam

    【讨论】:

    • 您通常为 steps_per_epoch 选择什么值?
    • 这取决于您的数据集大小和批量大小。在您的问题中,您说您想每两个时期更新一次。因此,假设您有 1000 个样本和 20 个批量大小,那么一个 epoch 将是 1000 / 20 = 50 步 (steps_per_epoch = 50)。
    • 在我的例子中,我有 1905 个样本,批量大小 = 32,所以 steps_per_epoch = 1905/32 = 59,53 => 60 ??
    • 是的。我认为decay_steps 需要是一个整数,因为staircase 参数基本上告诉ExponentialDecay 计划在您的图像计算的(global_step / decay_steps) 部分中进行整数除法。我会通过decay_steps=119 (59.5 * 2)。
    • 只有在 steps_per_epoch 不是 int 的情况下才会出现这种情况,但这既不是这里也不是那里。我的回答能回答你的问题吗?如果是这样,请考虑将其标记为这样。
    猜你喜欢
    • 2020-05-18
    • 2019-09-03
    • 1970-01-01
    • 2016-09-02
    • 2019-04-04
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多