Skip to content

Video understanding, tracking, generation, and world models · Action recognition · VID005 · Training method

Temporal Segment Networks (TSN)

Divides a video into temporal segments, samples a snippet from each and learns from a consensus of snippet scores.

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

Divides a video into temporal segments, samples a snippet from each and learns from a consensus of snippet scores. TSN provides economical whole-video coverage when processing every frame is unnecessary, especially for actions with evidence distributed across the recording.

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

training-method · Action recognition. Usually supervised video-label learning; image/video pretraining may use other supervision.

Architecture / computational structure

Shared snippet encoder with a video-level consensus operator over temporal segments.

Assumptions

Inputs must satisfy the temporal, modality and annotation protocol described below. Order-insensitive averaging can confuse reversed actions or multi-stage events. A video label need not apply to every sampled snippet, and short discriminative events may be missed.

Formula / computational definition

p(y∣V)=softmax⁡(G(f(x1),…,f(xK)))yp(y\mid V)=\operatorname{softmax}(G(f(x_1),\ldots,f(x_K)))_y, with KK segments, snippet encoder ff and consensus GG, often averaging. The loss supervises the aggregated video prediction rather than independent arbitrary snippets.

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: Tune segment count, snippet length, modality, consensus rule and training-versus-evaluation sampling.

Fitting, fine-tuning, and adaptation

Fit the consensus/head with frozen snippets, then adapt the encoder. Increase segment count to improve coverage but validate whether brief events are still missed. 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. Compare uniform, random and dense sampling at equal compute; report accuracy for short events and order-sensitive classes.

Example application

Classify long videos containing scattered evidence of an activity.

Interpretation / pitfalls

Watch out

An optimized training objective or a favorable example does not establish generalization. Compare uniform, random and dense sampling at equal compute; report accuracy for short events and order-sensitive classes. The example below isolates one mechanism and cannot substantiate a full-model benchmark claim.

Python and R code examples

Component: Aggregate segment-level logits before video supervision. 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: Use a shared frame/snippet encoder, stratified temporal sampling and differentiable consensus in PyTorch. R: Implement segment sampling and score aggregation directly in R; obtain neural snippet scores through a Python bridge.

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 — Aggregate segment-level logits before video supervision.

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()
logits = np.array([[3.,0.],[0.,2.],[2.,1.]])
consensus = logits.mean(axis=0)
prob = softmax(consensus)
print(prob, "video CE", -np.log(prob[0]))
R

Component demo, not a trained model — Aggregate segment-level logits before video supervision.

Shared setup for this chapter
softmax <- function(x) {
  e <- exp(x - max(x))
  e / sum(e)
}
logits <- matrix(c(3,0,0,2,2,1),3,byrow=TRUE)
prob <- softmax(colMeans(logits))
print(prob); print(-log(prob[1]))

Sources

From the CodeSplash reference, entry VID005.