Skip to content

Video understanding, tracking, generation, and world models · Video self-supervision · VID021 · Training method

Dense Predictive Coding (DPC)

Predicts future video representations from encoded past context and contrasts the predictions with other candidate features.

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

Predicts future video representations from encoded past context and contrasts the predictions with other candidate features. Dense spatial features preserve local information, making the task more specific than reconstructing one global video vector.

Question / objective

Learn transferable video representations from automatically constructed targets or weak cross-modal supervision. This is a learning or inference objective, not a test of a statistical null hypothesis.

Method type and supervision

training-method · Video self-supervision. Self-supervised pretraining; cross-modal variants also use weak paired language supervision.

Architecture / computational structure

Dense clip encoder, temporal context aggregator and future-feature predictor.

Assumptions

Inputs must satisfy the temporal, modality and annotation protocol described below. Negatives may be semantically similar or from nearby times. Predictability may favor static backgrounds; future supervision is permitted in training but must not leak into causal test inputs.

Formula / computational definition

L=−log⁡exp⁡(z^⊤z+/τ)∑jexp⁡(z^⊤zj/τ)L=-\log\frac{\exp(\hat z^\top z^+/\tau)}{\sum_j\exp(\hat z^\top z_j/\tau)} contrasts a predicted future feature z^\hat z with its true target z+z^+ and distractors zjz_j; τ\tau is a temperature when used.

Parameters and notation

Learned/estimated quantities: Encoder and predictor/projection weights are learned; target-network EMA values are state updates, and masks/negative policies are design choices. Symbols specific to the objective are defined with the equation. Hyperparameters and design choices: Prediction horizon, context length, spatial feature resolution, candidate construction and aggregator capacity matter.

Fitting, fine-tuning, and adaptation

Pretrain using domain video, then compare frozen probes with fine-tuning. Adapt the context horizon only with validation because easier prediction can reduce useful motion information. 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 frozen/fine-tuned transfer and vary prediction horizon; inspect performance on motion-sensitive versus appearance-dominated tasks.

Example application

Learn features for predicting upcoming action phases.

Interpretation / pitfalls

Watch out

An optimized training objective or a favorable example does not establish generalization. Measure frozen/fine-tuned transfer and vary prediction horizon; inspect performance on motion-sensitive versus appearance-dominated tasks. The example below isolates one mechanism and cannot substantiate a full-model benchmark claim.

Python and R code examples

Component: Contrast one predicted future feature against candidate futures. 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 an encoder, temporal context aggregator and dense contrastive target indexing. R: Compute candidate similarities and contrastive losses in R; train the full spatiotemporal encoder through R torch or 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 — Contrast one predicted future feature against candidate futures.

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()
prediction = np.array([1.,0.])
future_candidates = np.array([[.9,.1],[0.,1.],[-1.,0.]])
scores = future_candidates@prediction/0.2
print("future-prediction contrastive loss",-np.log(softmax(scores)[0]))
R

Component demo, not a trained model — Contrast one predicted future feature against candidate futures.

Shared setup for this chapter
softmax <- function(x) {
  e <- exp(x - max(x))
  e / sum(e)
}
prediction <- c(1,0)
future_candidates <- rbind(c(.9,.1),c(0,1),c(-1,0))
scores <- as.vector(future_candidates%*%prediction)/.2
print(-log(softmax(scores)[1]))

Sources

From the CodeSplash reference, entry VID021.