# tf.keras.layers.TimeDistributed

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/TimeDistributed) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/layers/wrappers.py#L83-L377) |

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

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

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.keras.layers.TimeDistributed`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/TimeDistributed)

<br />

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

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 = tf.keras.Input(shape=(10, 128, 128, 3))
    conv_2d_layer = tf.keras.layers.Conv2D(64, (3, 3))
    outputs = tf.keras.layers.TimeDistributed(conv_2d_layer)(inputs)
    outputs.shape
    TensorShape([None, 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 [`tf.keras.layers.Layer`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/keras/layers/Layer) instance. |

<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 />

| ## Raises ||
|---|---|
| `ValueError` | If not initialized with a [`tf.keras.layers.Layer`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/keras/layers/Layer) instance. |

<br />