Video understanding, tracking, generation, and world models · Action recognition · VID007 · Architecture
Non-local Neural Networks for Video
Adds interactions between distant space-time positions so evidence need not travel only through local convolutional neighborhoods.
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
Adds interactions between distant space-time positions so evidence need not travel only through local convolutional neighborhoods. In video recognition, a non-local block can relate an object in one frame to an actor or action cue much later in the clip.
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
Feature affinity, normalized non-local aggregation, value projection and residual connection.
Assumptions
Inputs must satisfy the temporal, modality and annotation protocol described below. All-pairs interactions can require quadratic memory. Attention to distant pixels is not proof of causal reasoning; background correlations remain available.
Formula / computational definition
, where are space-time positions, measures affinity, transforms values and normalizes the weights. A residual projection returns to the backbone.
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: Affinity type, projected channel dimension, subsampling of keys and insertion depth determine compute and receptive field.
Fitting, fine-tuning, and adaptation
Insert blocks into a pretrained backbone and initialize the residual pathway conservatively. Tune projections before unfreezing the backbone; inspect memory as token count rises. 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 to the same backbone without the block and report accuracy, memory and long-range temporal ablations.
Example application
Relate distant actor and object cues within a clip.
Interpretation / pitfalls
Watch out
An optimized training objective or a favorable example does not establish generalization. Compare to the same backbone without the block and report accuracy, memory and long-range temporal ablations. The example below isolates one mechanism and cannot substantiate a full-model benchmark claim.
Python and R code examples
Component: Non-local attention over three space-time positions. 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 the authors' SlowFast repository or implement affinity, normalization and value aggregation explicitly. R: Small non-local matrices are straightforward in R; use R torch or reticulate for trainable video backbones.
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 — Non-local attention over three space-time positions.
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.array([[1.,0.],[0.,1.],[1.,1.]])
affinity = x@x.T
weights = np.vstack([softmax(row) for row in affinity])
print(weights@x)
Component demo, not a trained model — Non-local attention over three space-time positions.
Shared setup for this chapter
softmax <- function(x) {
e <- exp(x - max(x))
e / sum(e)
}
x <- matrix(c(1,0,0,1,1,1),3,byrow=TRUE)
affinity <- x%*%t(x)
weights <- t(apply(affinity,1,softmax))
print(weights%*%x)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry VID007.