tf.keras.callbacks.LearningRateScheduler
Stay organized with collections
Save and categorize content based on your preferences.
Learning rate scheduler.
Inherits From: Callback
tf.keras.callbacks.LearningRateScheduler(
schedule, verbose=0
)
Arguments |
schedule
|
a function that takes an epoch index as input
(integer, indexed from 0) and returns a new
learning rate as output (float).
|
verbose
|
int. 0: quiet, 1: update messages.
|
# This function keeps the learning rate at 0.001 for the first ten epochs
# and decreases it exponentially after that.
def scheduler(epoch):
if epoch < 10:
return 0.001
else:
return 0.001 * tf.math.exp(0.1 * (10 - epoch))
callback = tf.keras.callbacks.LearningRateScheduler(scheduler)
model.fit(data, labels, epochs=100, callbacks=[callback],
validation_data=(val_data, val_labels))
Methods
set_model
View source
set_model(
model
)
set_params
View source
set_params(
params
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.callbacks.LearningRateScheduler\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/callbacks/LearningRateScheduler) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/python/keras/callbacks.py#L1564-L1613) |\n\nLearning rate scheduler.\n\nInherits From: [`Callback`](../../../tf/keras/callbacks/Callback)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.callbacks.LearningRateScheduler`](/api_docs/python/tf/keras/callbacks/LearningRateScheduler)\n\n\u003cbr /\u003e\n\n tf.keras.callbacks.LearningRateScheduler(\n schedule, verbose=0\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|------------|----------------------------------------------------------------------------------------------------------------------------|\n| `schedule` | a function that takes an epoch index as input (integer, indexed from 0) and returns a new learning rate as output (float). |\n| `verbose` | int. 0: quiet, 1: update messages. |\n\n\u003cbr /\u003e\n\n # This function keeps the learning rate at 0.001 for the first ten epochs\n # and decreases it exponentially after that.\n def scheduler(epoch):\n if epoch \u003c 10:\n return 0.001\n else:\n return 0.001 * tf.math.exp(0.1 * (10 - epoch))\n\n callback = tf.keras.callbacks.LearningRateScheduler(scheduler)\n model.fit(data, labels, epochs=100, callbacks=[callback],\n validation_data=(val_data, val_labels))\n\nMethods\n-------\n\n### `set_model`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/python/keras/callbacks.py#L548-L549) \n\n set_model(\n model\n )\n\n### `set_params`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/python/keras/callbacks.py#L545-L546) \n\n set_params(\n params\n )"]]