考虑以下信息:
初始学习率:0.0002
衰减系数:0.7
epoch数:70
我的问题是如何选择衰减步长,使得每两个epoch就进行一次衰减。我该如何在Keras中解决这个问题?
这是指数衰减学习率的公式:
考虑以下信息:
初始学习率:0.0002
衰减系数:0.7
epoch数:70
我的问题是如何选择衰减步长,使得每两个epoch就进行一次衰减。我该如何在Keras中解决这个问题?
这是指数衰减学习率的公式:
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 = 50
)。 - benbottodecay_steps
需要是一个整数,因为staircase
参数基本上告诉ExponentialDecay
调度在计算中从您的图像中的(global_step / decay_steps)
部分进行整数除法。我会传递decay_steps=119
(59.5 * 2)。 - benbottosteps_per_epoch
不是整数时才会出现这种情况,但这并不重要。我的回答是否解决了你的问题?如果是,请考虑将其标记为解决方案。 - benbottodecay_steps
是否为整数并不重要。如果staircase
为True
,代码只会执行floor
操作:https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/optimizer_v2/learning_rate_schedule.py#L185 - benbotto