<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/layers/rnn/time_distributed.py#L10-L141) |

This wrapper allows to apply a layer to every temporal slice of an input.

Inherits From: [`Wrapper`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Wrapper), [`Layer`](https://www.tensorflow.org/api_docs/python/tf/keras/Layer), [`Operation`](https://www.tensorflow.org/api_docs/python/tf/keras/Operation)

    tf.keras.layers.TimeDistributed(
        layer, **kwargs
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Load video data](https://www.tensorflow.org/tutorials/load_data/video) |

Every input should be at least 3D, and the dimension of index one of the
first input will be considered to be the temporal dimension.

Consider a batch of 32 video samples, where each sample is a 128x128 RGB
image with `channels_last` data format, across 10 timesteps.
The batch input shape is `(32, 10, 128, 128, 3)`.

You can then use `TimeDistributed` to apply the same `Conv2D` layer to each
of the 10 timesteps, independently:

    inputs = layers.Input(shape=(10, 128, 128, 3), batch_size=32)
    conv_2d_layer = layers.Conv2D(64, (3, 3))
    outputs = layers.TimeDistributed(conv_2d_layer)(inputs)
    outputs.shape
    (32, 10, 126, 126, 64)

Because `TimeDistributed` applies the same instance of `Conv2D` to each of
the timestamps, the same set of weights are used at each timestamp.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `layer` | a [`keras.layers.Layer`](https://www.tensorflow.org/api_docs/python/tf/keras/Layer) instance. |

<br />

<br />

<br />

<br />

| ## Call arguments ||
|---|---|
| `inputs` | Input tensor of shape (batch, time, ...) or nested tensors, and each of which has shape (batch, time, ...). |
| `training` | Python boolean indicating whether the layer should behave in training mode or in inference mode. This argument is passed to the wrapped layer (only if the layer supports this argument). |
| `mask` | Binary tensor of shape `(samples, timesteps)` indicating whether a given timestep should be masked. This argument is passed to the wrapped layer (only if the layer supports this argument). |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `input` | Retrieves the input tensor(s) of a symbolic operation. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |
| `output` | Retrieves the output tensor(s) of a layer. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |

<br />

## Methods

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/layers/core/wrapper.py#L38-L44)

    @classmethod
    from_config(
        config, custom_objects=None
    )

Creates an operation from its config.

This method is the reverse of `get_config`, capable of instantiating the
same operation from the config dictionary.

> [!NOTE]
> **Note:** If you override this method, you might receive a serialized dtype config, which is a `dict`. You can deserialize it as follows:

    if "dtype" in config and isinstance(config["dtype"], dict):
        policy = dtype_policies.deserialize(config["dtype"])

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, typically the output of `get_config`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An operation instance. ||

<br />