Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.TimeDistributed

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.

How it works

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.

Syntax

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

Parameters

NameTypeDescription
layerkeras.layers.LayerA Keras layer instance whose operation is applied independently to each temporal slice.

Returns

A tensor produced by applying the wrapped layer independently across the temporal dimension, retaining that dimension in the output.

Key points

  • Use it when the same operation should run independently on each time step.
  • Axis 1 is the time axis expected by the wrapper.
  • The constructor accepts an already-created Keras layer rather than a layer class name.
  • The primary input layout is batch, time, followed by the wrapped layer's feature dimensions.

Common mistakes

  • The input must have rank 3 or greater; axis 1 is interpreted as the temporal dimension.
  • The wrapper reuses one layer instance, so it does not create separate weights for different time steps.
  • training and mask are forwarded only when the wrapped layer supports those arguments.

Example: Apply Conv2D to every time step

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.

When to use it

Apply convolution independently to every frame

Video or image sequences

Transform each time step with a shared dense or normalization layer

Sequence feature processing

Reuse one layer across slices while preserving the time axis

Temporally structured inputs

Interview questions

QWhat does TimeDistributed do?

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.

QWhat are the main input and constructor requirements?

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.

QHow does the output shape relate to the input shape?

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.Layer
  • keras.layers.Conv2D
  • keras.layers.Input

Source: TimeDistributed layer. Checked 2026-10-15.