1tf.keras.callbacks.LearningRateScheduler(
2 schedule, verbose=0)
3
4# This function keeps the initial learning rate for the first ten epochs
5# and decreases it exponentially after that.
6
7def scheduler(epoch, lr):
8 if epoch < 10:
9 return lr
10 else:
11 return lr * tf.math.exp(-0.1)
12
13model = tf.keras.models.Sequential([tf.keras.layers.Dense(10)])
14model.compile(tf.keras.optimizers.SGD(), loss='mse')
15
16callback = tf.keras.callbacks.LearningRateScheduler(scheduler)
17history = model.fit(np.arange(100).reshape(5, 20), np.zeros(5),
18 epochs=15, callbacks=[callback], verbose=0)
19