LearningRateScheduler
类keras.callbacks.LearningRateScheduler(schedule, verbose=0)
学习率调度器。
在每个 epoch 开始时,此回调函数从 __init__
中提供的 schedule
函数获取更新后的学习率值(使用当前 epoch 和当前学习率),并将更新后的学习率应用于优化器。
参数
示例
>>> # This function keeps the initial learning rate for the first ten epochs
>>> # and decreases it exponentially after that.
>>> def scheduler(epoch, lr):
... if epoch < 10:
... return lr
... else:
... return lr * ops.exp(-0.1)
>>>
>>> model = keras.models.Sequential([keras.layers.Dense(10)])
>>> model.compile(keras.optimizers.SGD(), loss='mse')
>>> round(model.optimizer.learning_rate, 5)
0.01
>>> callback = keras.callbacks.LearningRateScheduler(scheduler)
>>> history = model.fit(np.arange(100).reshape(5, 20), np.zeros(5),
... epochs=15, callbacks=[callback], verbose=0)
>>> round(model.optimizer.learning_rate, 5)
0.00607