Recognizing actions: two streams and 3D convolution
Early action recognizers fed motion in as a second image (two-stream) or let filters slide through time (C3D, I3D, R(2+1)D). See what each adds, what it costs and how to tell if motion helped.
What runs in CodeSplash
- VID001Two-Stream Convolutional Networks Explained here
- VID002C3D Explained here
- VID003Inflated 3D ConvNet (I3D) Explained here
- VID004R(2+1)D Needs a data type CodeSplash doesn't load yet
You will be able to
- Describe a two-stream network and how its scores are fused
- Write a 3D convolution and say what its receptive field covers
- Explain filter inflation and why it preserves a still image's response
- Compare full 3D filters with factorized (2+1)D ones on a fair budget
Appearance and motion, separately
ReadA two-stream networkTwo-stream networkOne network reads the frames, a second reads stacked optical flow, and their class scores are blended. trains two image networks. One reads frames and recognizes objects and scenes. The other reads a stack of optical flowOptical flowFor each pixel, how far it moved between two frames, as a horizontal and a vertical shift in pixels. fields, the per-pixel motion between frames, and recognizes movement. Their class scores are blended:
In the reference's example, the frame stream favors the first class and the flow stream the second. With a little less weight on frames, the blend is 0.40, 0.47 and 0.13: motion tips the decision to the second class.
When motion lies
PredictPredict first
The camera pans slowly across a parked car. What does the flow stream see?
Reveal
Motion everywhere. Flow measures movement in the image, and a moving camera moves every pixel. Camera motion, cuts and lighting changes all contaminate the motion stream. And computing flow for every clip can cost more than the networks themselves.
Filters that slide through time
ReadA 3D convolution3D convolutionA filter that slides over time as well as height and width, so it can respond to short movements. extends a filter across time as well as rows and columns :
Stacked layers grow the receptive fieldReceptive fieldHow many past values one output of a convolutional network can see; for a TCN 1 + 2(k − 1)(2^B − 1). in time and space, so C3D learns short movements and appearance together. In the reference's toy, a 2×2×2 averaging filter over a 3×3×3 video gives outputs from 6.5 up to 19.5. Each output mixes two frames.
The arithmetic of one convolution layer: kernel, stride, padding and reach.
DExplorable · Convolution: kernel, stride, padding
What decides a convolution's output size, and which pixels does it actually read?
Layout
1-D stack: causal layers whose dilation grows, as in a TCN.
Input
Kernel
Pixels per side (the 1-D signal is 2n long).
How far the kernel moves between outputs (2-D).
Zeros added on each side (2-D).
Gap between kernel taps; in the 1-D stack layer l uses dˡ.
The receptive field grows with every layer.
Which output cell shows the pixels it reads (2-D).
- Positive
- Negative
- The highlighted output and the pixels it reads
- Output width
- 8
- Receptive field
- 5
- Weights per layer
- 10
- Input read
- 1.00
- Sum of outputs
- 0.00
- Puzzle: Keep the output the same size as the input with a 5 × 5 kernel and stride 1.
- Puzzle: In the 1-D stack, make the last output see at least 30 steps with a kernel of 3.
A 3 × 3 kernel with padding 1, stride 1 and dilation 1 turns 8 × 8 pixels into 8 × 8. Every input pixel is read. After 2 layers one output sees 5 × 5 pixels, with 10 weights per layer whatever the image size.
Borrow an image network
ReadVideo labels are scarce; image labels aren't. Filter inflationFilter inflationCopy a trained image filter across time and divide by the number of copies, so a still clip gives the image's response. (I3D) copies each trained 2D filter times along time and divides by :
Feed it a "boring video", one image repeated, and the 3D filter responds exactly as the image filter did. The reference checks this: the image response is −3.0 and the inflated clip response is −3.0. Training then teaches the copies to differ, which is how the network can learn motion.
import numpy as np
video = np.arange(27.).reshape(3, 3, 3) # time, row, column
k = np.ones((2, 2, 2)) / 8 # 3D averaging filter
c3d = np.array([[[np.sum(video[t:t+2, y:y+2, x:x+2] * k)
for x in range(2)] for y in range(2)] for t in range(2)])
image = np.array([[1., 2.], [3., 4.]]); w2 = np.array([[1., 0.], [0., -1.]])
w3 = np.repeat(w2[None], 3, axis=0) / 3 # inflate over 3 frames
clip = np.repeat(image[None], 3, axis=0) # a still image as a clip
print(c3d.ravel(), np.sum(image * w2), np.sum(clip * w3))video <- aperm(array(0:26, dim = c(3, 3, 3)), c(3, 2, 1)) # [t, y, x], as numpy
c3d <- c()
for (t in 1:2) for (y in 1:2) for (x in 1:2)
c3d <- c(c3d, mean(video[t:(t + 1), y:(y + 1), x:(x + 1)]))
image <- matrix(c(1, 2, 3, 4), 2, byrow = TRUE)
w2 <- matrix(c(1, 0, 0, -1), 2, byrow = TRUE)
print(c3d); print(c(sum(image * w2), 3 * sum(image * (w2 / 3))))Split space and time
ReadR(2+1)DFactorized space-time convolutionReplace one 3D filter with a spatial filter, a nonlinearity and then a temporal filter. replaces each 3D filter with a spatial filter, a nonlinearity, then a temporal filter:
The extra nonlinearity adds capacity at the same parameter count, and the split often trains more easily. In the reference's toy, spatial averaging and a ReLU give frame values 0.0, 1.5 and 5.5; a 3-tap temporal filter then gives 2.125.
Matching parameters doesn't match speed or memory. Measure latency and memory on the device you'll use.
Did motion help?
ReadEvery one of these models can score well from scenery alone: a pool means swimming. So a fair report includes:
- a frames-only baseline on the same split, beside the two-stream or 3D model;
- accuracy per class and per video after a stated way of combining clips;
- total cost, including flow extraction;
- for transfer from images or a large video dataset, the exact checkpoint, because its features carry that source's habits.
What runs here
Read| Entry | In CodeSplash |
|---|---|
| VID001 · Two-Stream Convolutional Networks | Explained here |
| VID002 · C3D | Explained here |
| VID003 · Inflated 3D ConvNet (I3D) | Explained here |
| VID004 · R(2+1)D | Needs a data type CodeSplash doesn't load yet (video) |
Check: two streams and 3D convolution
CheckpointCheck yourself
What does the second stream of a two-stream network read?
Show the answer
Answer: b
One stream sees appearance, the other sees motion as flow fields; their class scores are blended.
Check yourself
A two-stream model beats a frames-only model by two points. What else must you report before claiming motion helps?
Show the answer
Answer: b
Motion has to earn its cost on the same split. Flow extraction is part of the price.
Check yourself
What makes a convolution "3D" in C3D?
Show the answer
Answer: a
The filter slides over time too, so one output mixes neighboring frames.
Check yourself
You cut each training video into overlapping 16-frame clips for C3D. How should test clips be chosen?
Show the answer
Answer: b
Overlapping clips from one video are near-copies. Hold out whole videos.
Check yourself
Why does I3D divide an inflated filter by the number of frames it spans?
Show the answer
Answer: b
Dividing by T keeps the response to a still clip unchanged, so the image network's knowledge carries over at the start.
Check yourself
An inflated network starts from image weights. What does that guarantee about motion?
Show the answer
Answer: b
At the start every time slice is the same filter. Motion sensitivity comes only from training on video.
Check yourself
How does R(2+1)D replace a full 3D filter?
Show the answer
Answer: b
Factorizing separates appearance from motion and adds a nonlinearity between them.
Check yourself
An R(2+1)D model has the same number of parameters as a 3D model. Can you assume it runs as fast?
Show the answer
Answer: b
Parameter counts don't fix memory traffic or speed. Compare on the hardware you'll deploy to.
Recap
Recap- Two-stream networks read frames and optical flow separately and blend the scores; flow costs time and is fooled by camera motion.
- 3D convolutions slide through time; neighboring clips are near-copies, so split by video.
- Inflation (I3D) starts a video network from image filters; factorization (R(2+1)D) splits space from time.
- Report a frames-only baseline, per-class results and total cost.
Concepts in this lesson