Video understanding, tracking, generation, and world models · Action recognition · VID010 · Architecture
TimeSformer
Applies transformer attention to video patches, with divided temporal and spatial attention as an effective design.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- The reference's example ran here in one language.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Applies transformer attention to video patches, with divided temporal and spatial attention as an effective design. Temporal attention links the same spatial patch location across frames, and spatial attention then exchanges information within frames.
Question / objective
Estimate an action label from a clip or video and determine which temporal evidence improves prediction. This is a learning or inference objective, not a test of a statistical null hypothesis.
Method type and supervision
architecture · Action recognition. Usually supervised video-label learning; image/video pretraining may use other supervision.
Architecture / computational structure
Patch embedding and transformer blocks with divided temporal and spatial attention.
Assumptions
Inputs must satisfy the temporal, modality and annotation protocol described below. Patch correspondence is not true motion tracking; moving objects cross patch locations. Long clips still require substantial memory and are sensitive to frame sampling.
Formula / computational definition
; divided attention applies and sequentially rather than one full attention over all tokens. counts frames, patches and key dimensions.
Parameters and notation
Learned/estimated quantities: Encoder filters or attention/projection weights, normalization parameters and task-head coefficients are learned; architectural dimensions and sampling rules are chosen. Symbols specific to the objective are defined with the equation. Hyperparameters and design choices: Patch size, clip length, embedding width, attention heads, positional embeddings and initialization are central.
Fitting, fine-tuning, and adaptation
Tune the classifier first, then temporal attention and later spatial blocks. LoRA can target attention projections in a compatible implementation; validate performance against full fine-tuning. Use a separate adaptation validation split, monitor the target metric and retention of previously useful behavior, and save the exact preprocessing and training configuration.
How to use and calibrate
Fix the input protocol and target before fitting; choose design settings on held-out source videos, then freeze the evaluation procedure. Report accuracy, long-range temporal tasks and memory scaling; test shuffled-frame controls to measure temporal reliance.
Example application
Recognize an action requiring information across many sampled frames.
Interpretation / pitfalls
Watch out
An optimized training objective or a favorable example does not establish generalization. Report accuracy, long-range temporal tasks and memory scaling; test shuffled-frame controls to measure temporal reliance. The example below isolates one mechanism and cannot substantiate a full-model benchmark claim.
Python and R code examples
Component: Factor attention into temporal and spatial token groups. Dependencies: NumPy in Python; base R in R; run the shared setup above. Python component: executed successfully. R component: unexecuted. No complete model training or pretrained inference was executed.
Full implementation route — Python: Implement divided attention or reproduce the paper-linked model, carefully preserving token ordering. R: Use reticulate for the encoder; R can inspect attention summaries but attention weights alone do not establish explanations.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Factor attention into temporal and spatial token groups.
Shared setup for this chapter
import numpy as np
def softmax(x):
z = np.asarray(x, dtype=float)
e = np.exp(z - z.max())
return e / e.sum()
x = np.arange(8.,dtype=float).reshape(2,2,2)/8 # T,P,C
attend = lambda a: np.vstack([softmax(r) for r in a@a.T])@a
temporal = np.stack([attend(x[:,p,:]) for p in range(2)],axis=1)
out = np.stack([attend(temporal[t]) for t in range(2)])
print(out)
Component demo, not a trained model — Factor attention into temporal and spatial token groups.
Shared setup for this chapter
softmax <- function(x) {
e <- exp(x - max(x))
e / sum(e)
}
x <- array(0,c(2,2,2))
for(t in 1:2) for(p in 1:2) for(c in 1:2) x[t,p,c] <- ((t-1)*4+(p-1)*2+c-1)/8
attend <- function(a) t(apply(a%*%t(a),1,softmax))%*%a
temp <- x; out <- x
for(p in 1:2) temp[,p,] <- attend(x[,p,])
for(t in 1:2) out[t,,] <- attend(temp[t,,])
print(out)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry VID010.