rslearn.models.temporal_transformer¶
temporal_transformer ¶
Transformer over the token dimension of a TokenFeatureMaps.
TemporalTransformer ¶
Bases: IntermediateComponent
Apply a per-spatial-patch transformer on the tokens at each patch.
Given a BCHWN token feature map, apply a transformer independently at each (b, h, w) location over the N tokens. Usually these are per-timestep tokens. This component is most useful if the underlying encoder does not perform any temporal reasoning, e.g. if the per-timestep tokens are derived by concatenating the outputs of a single-timestep model across timesteps in an image time series.
The output has the same shape as the input. If the input TokenFeatureMaps has masks, invalid tokens are excluded from attention (as key padding) and the masks are passed through unchanged to the output.
Source code in rslearn/models/temporal_transformer.py
forward ¶
forward(intermediates: Any, context: ModelContext) -> TokenFeatureMaps
Contextualize the tokens in each feature map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intermediates
|
Any
|
the output from the previous component, which must be a TokenFeatureMaps. |
required |
context
|
ModelContext
|
the model context. |
required |
Returns:
| Type | Description |
|---|---|
TokenFeatureMaps
|
a TokenFeatureMaps with the same shapes (and masks) as the input. |