# tf.keras.optimizers.schedules.LearningRateSchedule

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/optimizers/schedules/learning_rate_schedule.py#L30-L98) |

The learning rate schedule base class.

#### View aliases


**Main aliases**

[`tf.optimizers.schedules.LearningRateSchedule`](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/LearningRateSchedule)
**Compat aliases for migration**

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

\`tf.compat.v1.keras.optimizers.schedules.LearningRateSchedule\`

<br />

You can use a learning rate schedule to modulate how the learning rate
of your optimizer changes over time.

Several built-in learning rate schedules are available, such as
[`tf.keras.optimizers.schedules.ExponentialDecay`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/optimizers/schedules/ExponentialDecay) or
[`tf.keras.optimizers.schedules.PiecewiseConstantDecay`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/optimizers/schedules/PiecewiseConstantDecay):

    lr_schedule = keras.optimizers.schedules.ExponentialDecay(
        initial_learning_rate=1e-2,
        decay_steps=10000,
        decay_rate=0.9)
    optimizer = keras.optimizers.SGD(learning_rate=lr_schedule)

A `LearningRateSchedule` instance can be passed in as the `learning_rate`
argument of any optimizer.

To implement your own schedule object, you should implement the `__call__`
method, which takes a `step` argument (scalar integer tensor, the
current training step count).
Like for any other Keras object, you can also optionally
make your object serializable by implementing the `get_config`
and `from_config` methods.

#### Example:

    class MyLRSchedule(tf.keras.optimizers.schedules.LearningRateSchedule):

      def __init__(self, initial_learning_rate):
        self.initial_learning_rate = initial_learning_rate

      def __call__(self, step):
         return self.initial_learning_rate / (step + 1)

    optimizer = tf.keras.optimizers.SGD(learning_rate=MyLRSchedule(0.1))

## Methods

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/optimizers/schedules/learning_rate_schedule.py#L88-L98)

    @classmethod
    from_config(
        config
    )

Instantiates a `LearningRateSchedule` from its config.

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | Output of `get_config()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `LearningRateSchedule` instance. ||

<br />

### `get_config`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/optimizers/schedules/learning_rate_schedule.py#L81-L86)

    @abc.abstractmethod
    get_config()

### `__call__`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/optimizers/schedules/learning_rate_schedule.py#L74-L79)

    @abc.abstractmethod
    __call__(
        step
    )

Call self as a function.