# tf.keras.callbacks.LearningRateScheduler

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.10.0/keras/callbacks.py#L2135-L2204) |

Learning rate scheduler.

Inherits From: [`Callback`](https://www.tensorflow.org/versions/r2.10/api_docs/python/tf/keras/callbacks/Callback)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

\`tf.compat.v1.keras.callbacks.LearningRateScheduler\`

<br />

    tf.keras.callbacks.LearningRateScheduler(
        schedule, verbose=0
    )

At the beginning of every epoch, this callback gets the updated learning
rate value from `schedule` function provided at `__init__`, with the current
epoch and current learning rate, and applies the updated learning rate on
the optimizer.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `schedule` | a function that takes an epoch index (integer, indexed from 0) and current learning rate (float) as inputs and returns a new learning rate as output (float). |
| `verbose` | int. 0: quiet, 1: update messages. |

<br />

#### Example:

    # 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 * tf.math.exp(-0.1)

    model = tf.keras.models.Sequential([tf.keras.layers.Dense(10)])
    model.compile(tf.keras.optimizers.SGD(), loss='mse')
    round(model.optimizer.lr.numpy(), 5)
    0.01

    callback = tf.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.lr.numpy(), 5)
    0.00607

## Methods

### `set_model`

[View source](https://github.com/keras-team/keras/tree/v2.10.0/keras/callbacks.py#L682-L683)

    set_model(
        model
    )

### `set_params`

[View source](https://github.com/keras-team/keras/tree/v2.10.0/keras/callbacks.py#L679-L680)

    set_params(
        params
    )