Apply convolution independently to every frame
Video or image sequences
Keras · Class
TimeDistributed applies one Keras layer independently to every temporal slice of an input. The same layer instance—and therefore the same weights—is reused at each time step.
TimeDistributed wraps a layer and applies it independently to each temporal slice. The wrapped layer instance is reused at every time step, so all slices share the same weights; inputs must have at least three dimensions, with axis 1 treated as time.
keras.layers.TimeDistributed(layer, **kwargs)| Name | Type | Description |
|---|---|---|
layer | keras.layers.Layer | A Keras layer instance whose operation is applied independently to each temporal slice. |
A tensor produced by applying the wrapped layer independently across the temporal dimension, retaining that dimension in the output.
from keras import layers
inputs = layers.Input(shape=(10, 128, 128, 3))
conv = layers.Conv2D(64, (3, 3))
outputs = layers.TimeDistributed(conv)(inputs)
print(outputs.shape) # (None, 10, 126, 126, 64)Applies one shared Conv2D layer independently to each of 10 time steps.
Video or image sequences
Sequence feature processing
Temporally structured inputs
TimeDistributed applies a wrapped layer separately to every temporal slice of an input. For an input shaped (batch, time, ...), it preserves the time axis and applies the layer to each slice independently.
Follow-up: How are parameters handled across time? The same wrapped layer instance is reused, so every time step uses shared weights.
The wrapped layer must be a keras.layers.Layer instance. The input must have at least three dimensions, and dimension 1 is treated as the temporal axis.
Follow-up: What happens if the time axis is elsewhere? Rearrange the input so the temporal dimension is axis 1 before applying the wrapper.
For an input shaped (batch, time, ...), the wrapper produces outputs with the corresponding time dimension retained. In the documented example, (32, 10, 128, 128, 3) becomes (32, 10, 126, 126, 64) after a shared Conv2D(64, (3, 3)).
Follow-up: Can masking be used? A binary (samples, timesteps) mask can be passed and is forwarded when the wrapped layer supports masking.
keras.layers.Layerkeras.layers.Conv2Dkeras.layers.Input