Skip to content

Video understanding, tracking, generation, and world models · Action recognition · VID006 · Architecture

Temporal Shift Module (TSM)

Moves a subset of feature channels to neighboring time steps before applying ordinary spatial operations. The shift lets a largely 2D network exchange temporal information without introducing a learned 3D convolution,…

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

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 in Python and R here, and they agree.
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

Moves a subset of feature channels to neighboring time steps before applying ordinary spatial operations. The shift lets a largely 2D network exchange temporal information without introducing a learned 3D convolution, useful when deployment cost is a central constraint.

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

Spatial residual backbone with channel-shift operations inserted between temporal feature tensors.

Assumptions

Inputs must satisfy the temporal, modality and annotation protocol described below. Bidirectional shifting uses future frames and is unsuitable for strict online prediction without modification. Zero extra arithmetic does not mean zero memory movement or latency.

Formula / computational definition

x~t,c=xt−1,c\tilde x_{t,c}=x_{t-1,c} for one channel group, xt+1,cx_{t+1,c} for another and xt,cx_{t,c} otherwise. A subsequent learned spatial layer mixes the groups; the classifier uses supervised cross-entropy.

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: Choose shifted-channel fraction, insertion locations, number of frames and causal versus bidirectional shifting.

Fitting, fine-tuning, and adaptation

Fit a new head, then adapt spatial blocks that mix shifted channels. The shift has no learned weights; tune its fraction and causal layout as hyperparameters. 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. Measure end-to-end latency, memory traffic and accuracy at matched frame counts; verify online timing separately.

Example application

Run action recognition on devices that cannot afford full 3D convolutions.

Interpretation / pitfalls

Watch out

An optimized training objective or a favorable example does not establish generalization. Measure end-to-end latency, memory traffic and accuracy at matched frame counts; verify online timing separately. The example below isolates one mechanism and cannot substantiate a full-model benchmark claim.

Python and R code examples

Component: Shift channel groups across time with zero boundary padding. 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 a tensor shift inside residual blocks, avoiding unintended in-place gradient modifications. R: Demonstrate the shift with R arrays; train an R torch port or call the full Python architecture through reticulate.

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.

Python

Component demo, not a trained model — Shift channel groups across time with zero boundary padding.

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(12).reshape(4,3)
y = x.copy()
y[:,0] = 0; y[1:,0] = x[:-1,0]  # past
y[:,1] = 0; y[:-1,1] = x[1:,1]  # future: offline only
print(y)
R

Component demo, not a trained model — Shift channel groups across time with zero boundary padding.

Shared setup for this chapter
softmax <- function(x) {
  e <- exp(x - max(x))
  e / sum(e)
}
x <- matrix(0:11,4,byrow=TRUE); y <- x
y[,1] <- 0; y[2:4,1] <- x[1:3,1]
y[,2] <- 0; y[1:3,2] <- x[2:4,2] # future: offline only
print(y)

Sources

From the CodeSplash reference, entry VID006.