AI Logic

Architectures

SlowFast

Updated:

Architecture of SlowFast. The left side shows the overall flow (from a 64-frame clip, the Slow pathway takes 4 frames every 16 frames and the Fast pathway takes 32 frames every 2 frames, and ResNet conv1 through res5 are processed in two columns. Fast is a thin column with 1/8 of the channels and is concatenated into Slow through lateral connections after pool1, res2, res3, and res4; finally both are globally average-pooled, concatenated, and fed to a fully connected layer). The right side shows the three forms of the lateral connection (time-to-channel, time-strided sampling, and time-strided convolution)

Background and overview

SlowFast is a video recognition network that processes the same video clip with two pathways, a Slow pathway that looks at a low frame rate and a Fast pathway that looks at a high frame rate, and passes information from Fast to Slow through lateral connections. The Slow pathway captures "what is in the scene" (objects, places, and so on), while the Fast pathway, made lightweight with fewer channels, captures "how things move". It was presented at ICCV 2019 by Feichtenhofer, Fan, Malik, and He of Facebook AI Research (FAIR).

In images it is natural to treat height and width symmetrically, but time and space in video are not equivalent. The paper focuses on the following points.

  • Appearance changes slowly: a "hand" remains a hand while it waves, and a "person" remains a person when they go from walking to running. The category and color of objects can be captured well enough from sparse frames.
  • Motion changes quickly: actions such as clapping, waving, and jumping are hard to capture without fine temporal resolution.

Unlike 3D CNNs that treat space and time symmetrically (C3D, I3D, etc.), SlowFast therefore splits the roles between two temporal speeds. Two-Stream ConvNets also have two streams, but SlowFast does not use optical flow and is trained jointly from RGB frames alone.

The main results of the paper are as follows.

  • On Kinetics-400 it achieved 79.8% top-1 (without ImageNet pre-training), surpassing the previous best by 2.1 points and the best method without pre-training by 5.9 points.
  • Although the Fast pathway uses only about 20% of the computation, it improved Kinetics-400 accuracy by up to 3.4 points over a Slow-only model.
  • In human action detection (AVA), adding the Fast pathway improved results by 5.2 mAP (28% relative). The team won first place in the AVA action detection track of the ActivityNet Challenge 2019 with this method.

The paper cites as one source of inspiration the fact that primate retinal ganglion cells include P-cells (about 80%), which slowly capture fine shape and color, and M-cells (about 15–20%), which respond to fast changes but are insensitive to shape and color (while cautioning that the analogy is loose).

Theory: viewing at two frame rates and merging with lateral connections

Slow pathway (Section 3.1)

The input frames are subsampled with a large temporal stride τ\tau, processing only one frame out of every τ\tau. Typically τ=16\tau = 16, which for a 30 fps video is about 2 frames per second. If the Slow pathway samples TT frames, the original clip has T×τT \times \tau frames.

Fast pathway (Section 3.2)

The same clip as Slow is sampled with a smaller stride τ/α\tau / \alpha (α>1\alpha > 1). The number of frames is αT\alpha T, α\alpha times denser than Slow. Typically α=8\alpha = 8. The Fast pathway has the following three properties.

  1. High frame rate: it sees α\alpha times as many frames as Slow.
  2. High temporal resolution is preserved: no temporal pooling or temporally strided convolution is used until the final global average pooling. The features always have a temporal length of αT\alpha T frames.
  3. Fewer channels: the number of channels is β\beta times that of Slow (β<1\beta < 1, typically 1/81/8). Since the cost of convolution falls roughly with the square of the channel ratio, the Fast pathway takes only about 20% of the total computation.

With fewer channels, the Fast pathway has less capacity to represent spatial information. The paper considers this trade-off, weakening spatial representation in favor of temporal representation, desirable for the Fast pathway.

Lateral connections (Sections 3.3–3.4)

The information from the two pathways is fused through lateral connections. One unidirectional connection from Fast to Slow is placed at each ResNet stage boundary (right after pool1, res2, res3, and res4). With Slow features of shape {T,S2,C}\{T, S^2, C\} and Fast features of shape {αT,S2,βC}\{\alpha T, S^2, \beta C\}, the temporal lengths differ, so one of the following transformations is applied on the Fast side before summing or concatenating into Slow (right side of the figure at the top of the article).

  1. Time-to-channel: pack α\alpha frames into the channels of one frame, giving {T,S2,αβC}\{T, S^2, \alpha\beta C\}.
  2. Time-strided sampling: take one frame out of every α\alpha, giving {T,S2,βC}\{T, S^2, \beta C\}.
  3. Time-strided convolution: apply a 3D convolution of size 5×125 \times 1^2 with 2βC2\beta C output channels and temporal stride α\alpha (the default).

Finally, the output of each pathway is globally average-pooled, and the two vectors are concatenated and fed into a fully connected classification layer.

Example with ResNet-50 (Table 1 of the paper. T×τ=4×16T \times \tau = 4 \times 16, α=8\alpha = 8, β=1/8\beta = 1/8. Left side of the figure at the top of the article)

StageSlow pathway (4 frames)Fast pathway (32 frames)
Input4 frames, every 16th of 64 frames32 frames, every 2nd of 64 frames
conv11×721 \times 7^2, 645×725 \times 7^2, 8
pool11×321 \times 3^2 max1×321 \times 3^2 max
res2[1×12,64; 1×32,64; 1×12,256]×3[1 \times 1^2, 64;\ 1 \times 3^2, 64;\ 1 \times 1^2, 256] \times 3[3×12,8; 1×32,8; 1×12,32]×3[3 \times 1^2, 8;\ 1 \times 3^2, 8;\ 1 \times 1^2, 32] \times 3
res3[1×12,128; 1×32,128; 1×12,512]×4[1 \times 1^2, 128;\ 1 \times 3^2, 128;\ 1 \times 1^2, 512] \times 4[3×12,16; 1×32,16; 1×12,64]×4[3 \times 1^2, 16;\ 1 \times 3^2, 16;\ 1 \times 1^2, 64] \times 4
res4[3×12,256; 1×32,256; 1×12,1024]×6[3 \times 1^2, 256;\ 1 \times 3^2, 256;\ 1 \times 1^2, 1024] \times 6[3×12,32; 1×32,32; 1×12,128]×6[3 \times 1^2, 32;\ 1 \times 3^2, 32;\ 1 \times 1^2, 128] \times 6
res5[3×12,512; 1×32,512; 1×12,2048]×3[3 \times 1^2, 512;\ 1 \times 3^2, 512;\ 1 \times 1^2, 2048] \times 3[3×12,64; 1×32,64; 1×12,256]×3[3 \times 1^2, 64;\ 1 \times 3^2, 64;\ 1 \times 1^2, 256] \times 3
OutputGlobal average pooling → concat → fully connected(same as left)

Kernel sizes are written as "time × space², channels". In the Slow pathway, only res4 and res5 have convolutions with a temporal size greater than 1; conv1 through res3 are effectively 2D convolutions. The paper reports that using temporal convolutions in early layers reduced accuracy. It reasons that, with widely spaced frames, there is little temporal correlation until the deeper layers where the spatial receptive field becomes large enough. The Fast pathway has temporal convolutions in every block.

Training (Section 4 and appendix)

  • On Kinetics, the model is trained from scratch without ImageNet pre-training (with pre-training, results were comparable, within ±0.3%).
  • A clip of αT×τ\alpha T \times \tau frames is randomly sampled from the video, the shorter side is resized to a random value between 256 and 320, and a 224 × 224 crop is randomly taken, with random horizontal flipping.
  • Synchronous SGD (momentum 0.9, Weight Decay 10−410^{-4}, mini-batch 1024). The learning rate follows a half-period cosine schedule, η⋅0.5[cos⁡(nnmaxπ)+1]\eta \cdot 0.5[\cos(\frac{n}{n_{max}}\pi) + 1] at iteration nn (η=1.6\eta = 1.6), with warmup for the first 8,000 iterations. Dropout of 0.5 is applied before the final classification layer.

Inference (Section 4)

Ten clips are sampled uniformly along the time axis of the video; for each, the shorter side is resized to 256 and three 256 × 256 crops are taken (30 "views"). The softmax scores are averaged for the prediction.

Why splitting into two speeds works

1. The Fast pathway is weak on its own but complements Slow

On Kinetics-400, the Slow-only model reached 72.6% top-1 (27.3 GFLOPs), and the Fast-only model 51.7% (6.4 GFLOPs). Yet combining the two with lateral connections gives 75.6%, 3.0 points higher than Slow alone. The paper states that the Fast pathway represents motion information that is largely complementary to what Slow has.

2. Spatial information is left to Slow, so Fast can be light

Varying the Fast pathway's channel ratio β\beta from 1/41/4 to 1/321/32, every setting was better than the Slow-only model. With β=1/32\beta = 1/32, the Fast pathway adds only 1.3 GFLOPs (about 5%), yet accuracy improved by 1.6 points.

Changing the Fast pathway's input to something with even less spatial information barely reduced accuracy.

  • Grayscale frames: 75.5% (almost the same as 75.6% with RGB, with about 5% less computation). This also matches the behavior of M-cells, which are insensitive to color.
  • Half resolution (β=1/4\beta = 1/4): 74.7%.
  • Difference from the previous frame: 74.5%.
  • Optical flow: 73.8%.

As an everyday analogy, the Slow pathway is the person who takes a photo every few seconds and carefully examines "what is in it", while the Fast pathway is the person who watches a continuous stream of coarse black-and-white frames and tracks only "how things moved". The motion tracker does not need to see fine shapes, so it gets by with little effort.

3. Temporal resolution is not reduced

The Fast pathway does not shrink along the time axis until the end, so the timing of fine motions is preserved into the deep layers. In AVA action detection, adding the Fast pathway improved 57 of the 60 classes, with especially large gains for fast motions such as "clap" (+27.7 AP).

For the same computation, adding the Fast pathway is more efficient than increasing the frames of the Slow pathway. In Figure 2 of the paper, doubling the frames of a Slow-only model doubles its computation, whereas SlowFast, with little additional computation, achieves higher accuracy than Slow-only models that see more frames.

Experimental results

Comparison on Kinetics-400 (excerpt from Table 2 of the paper. "Compute" is GFLOPs per view × number of views)

ModelFlowPre-trainingtop-1top-5Compute
I3D―ImageNet72.190.3108 × N/A
Two-stream I3DYesImageNet75.792.0216 × N/A
Nonlocal R101―ImageNet77.793.3359 × 30
R(2+1)D―None72.090.0152 × 115
R(2+1)D (two-stream)YesNone73.990.9304 × 115
SlowFast 4×16, R50―None75.692.136.1 × 30
SlowFast 8×8, R50―None77.092.665.7 × 30
SlowFast 8×8, R101―None77.993.2106 × 30
SlowFast 16×8, R101―None78.993.5213 × 30
SlowFast 16×8, R101 + NL―None79.893.9234 × 30

"4×16" is the Slow pathway's T×τT \times \tau, R50 and R101 are ResNet-50 and -101, and NL denotes Non-local blocks. SlowFast surpassed the previous best without pre-training or optical flow.

Kinetics-600 and Charades (Tables 3 and 4 of the paper)

DatasetModelMetricValue
Kinetics-600I3Dtop-171.9
Kinetics-600StNet-IRv2 RGB (winner of ActivityNet Challenge 2018)top-179.0
Kinetics-600SlowFast 16×8, R101 + NLtop-181.8
CharadesSlow only (pre-trained on Kinetics-400)mAP39.0
CharadesSlowFast (pre-trained on Kinetics-400)mAP42.1
CharadesSlowFast + NL (pre-trained on Kinetics-600)mAP45.2

Comparison of Fast pathway designs (Kinetics-400, 4×16, R50. Table 5 of the paper)

Settingtop-1GFLOPs
Slow only72.627.3
Fast only51.76.4
SlowFast (no lateral connections, concatenation at the end only)73.534.2
SlowFast (time-to-channel, sum)74.534.2
SlowFast (time-to-channel, concat)74.339.8
SlowFast (time-strided sampling)75.434.9
SlowFast (time-strided convolution)75.636.1
β=1/4\beta = 1/475.654.5
β=1/6\beta = 1/675.841.8
β=1/8\beta = 1/8 (default)75.636.1
β=1/32\beta = 1/3274.228.6

Action detection on AVA (mAP on the AVA v2.1 validation set. Table 7 of the paper)

ModelFlowPre-trainingmAP
I3D―Kinetics-40014.5
I3DYesKinetics-40015.6
ATR, R50 + NLYesKinetics-40021.7
SlowFast―Kinetics-40026.3
SlowFast + NL―Kinetics-60027.3

For detection, SlowFast is used as the backbone in a form similar to Faster R-CNN, and features of person regions are extracted with RoIAlign from the last feature map of res5.

Practical considerations

Keep the following points in mind when using SlowFast.

  • Match τ\tau and α\alpha to the frame rate: τ=16\tau = 16 (about 2 frames per second at 30 fps) and α=8\alpha = 8 are values tailored to the videos in the paper. For videos with very different frame rates, recompute how many seconds apart Slow and Fast actually sample, and choose accordingly.
  • Keep the early layers of the Slow pathway 2D: using temporal convolutions in conv1–res3 of the Slow pathway reduced accuracy. When building a Slow pathway on other networks, a good rule of thumb is to place temporal convolutions only in the deeper layers.
  • Multiply inference compute by the number of views: the accuracy in the paper is the average over 30 views (10 clips × 3 crops) per video. The GFLOPs in the tables are per view, so actual inference costs 30 times that.
  • Training settings matter when training from scratch: the paper shows that the same 3D ResNet-50 reaches only 69.4% when trained from scratch with the settings of prior work, but 73.5% with the paper's settings (large mini-batch, cosine schedule, warmup).

The paper's training on Kinetics assumes very large compute. It trains for 196–256 epochs with a mini-batch of 1024, which is hard to reproduce as is with small compute resources. For small datasets, fine-tuning from weights trained on Kinetics is the practical approach (the paper also trains on Charades and AVA starting from Kinetics weights).

Comparison with other models

Video action recognition models compare as follows.

ModelConvolutionHow motion is capturedTemporal coverageOptical flowPre-training
Two-Stream ConvNets2DFlow stream (same network shape)1 RGB frame + 10 flow pairsRequiredImageNet
C3D3D (all 3×3×3)3D convolution in every layer16 consecutive framesNot neededSports-1M
TSN2DPer-segment snippets + flow streamSparse over the whole videoUsed (RGB only also possible)ImageNet
I3D3D (inflated Inception-v1)3D convolution + flow stream64 consecutive framesUsed (RGB only also possible)ImageNet + Kinetics
TSM2DShifts part of the channels along timeSparse 8–16 framesNot neededImageNet
SlowFast3D (early Slow layers are 2D)Lightweight high-frame-rate Fast pathwayA 64-frame span as 4 and 32 framesNot neededNone (from scratch)

As a rule of thumb:

  • For high accuracy without optical flow: SlowFast is a good fit. In the paper, it beat the flow-based two-stream I3D (75.7% on Kinetics-400) using RGB alone (75.6–79.8%).
  • For human action detection (where, who, and what): detectors built on SlowFast improved greatly on AVA.
  • To minimize computation or run on edge devices: TSM, which runs at the cost of a 2D CNN, is a good fit. Even the lightest SlowFast (4×16, R50) costs 36.1 GFLOPs per view, comparable to 8-frame TSM (33 GFLOPs) (input sizes and measurement methods differ between papers), but it includes 3D convolutions.

PyTorch example

Show code
python
import torch
import torch.nn as nn

"""
Skeleton implementation of SlowFast (Feichtenhofer et al. 2019, Sections 3.1–3.4, Table 1)
Input: a 64-frame clip (N, 3, 64, H, W). The contents of each stage (ResNet blocks) are simplified.
"""


def sample_pathways(clip, tau=16, alpha=8):
  """Slow takes T frames every tau frames; Fast takes alpha*T frames every tau/alpha frames."""
  slow = clip[:, :, ::tau]               # (N, 3, T, H, W)      T = 64 / 16 = 4
  fast = clip[:, :, ::tau // alpha]      # (N, 3, alpha*T, H, W) = 32 frames
  return slow, fast


def stage(cin, cout, t_kernel):
  """Stand-in for one stage. t_kernel = 1 is effectively 2D; 3 also convolves along time.
  Temporal stride is 1 (the Fast pathway does not shrink along time)."""
  return nn.Sequential(
    nn.Conv3d(cin, cout, (t_kernel, 3, 3), stride=(1, 2, 2), padding=(t_kernel // 2, 1, 1), bias=False),
    nn.BatchNorm3d(cout), nn.ReLU(inplace=True),
  )


class Lateral(nn.Module):
  """Lateral connection (time-strided convolution): 5×1², 2βC outputs, temporal stride α."""

  def __init__(self, c_fast, alpha=8):
    super().__init__()
    self.conv = nn.Conv3d(c_fast, 2 * c_fast, (5, 1, 1), stride=(alpha, 1, 1), padding=(2, 0, 0), bias=False)

  def forward(self, x_slow, x_fast):
    return torch.cat([x_slow, self.conv(x_fast)], dim=1)   # Concatenate into Slow


class SlowFast(nn.Module):
  def __init__(self, num_classes=400, alpha=8, beta_inv=8):
    super().__init__()
    cs = [64, 256, 512, 1024, 2048]          # Output channels of each Slow stage (Table 1)
    cf = [c // beta_inv for c in cs]         # Fast uses β = 1/8 of them
    tk_slow = [1, 1, 1, 3, 3]                # Slow: temporal convolution only in res4 and res5
    tk_fast = [5, 3, 3, 3, 3]                # Fast: 5 for conv1; other stages also convolve along time
    self.slow, self.fast, self.lat = nn.ModuleList(), nn.ModuleList(), nn.ModuleList()
    s_in, f_in = 3, 3
    for i in range(5):
      self.slow.append(stage(s_in, cs[i], tk_slow[i]))
      self.fast.append(stage(f_in, cf[i], tk_fast[i]))
      s_in, f_in = cs[i], cf[i]
      if i < 4:                              # Lateral connections right after conv1(pool1), res2, res3, res4
        self.lat.append(Lateral(cf[i], alpha))
        s_in += 2 * cf[i]                    # The next Slow stage's input grows by the concatenated channels
    self.pool = nn.AdaptiveAvgPool3d(1)
    self.dropout = nn.Dropout(0.5)          # Before the classifier (appendix)
    self.fc = nn.Linear(cs[-1] + cf[-1], num_classes)

  def forward(self, clip):
    xs, xf = sample_pathways(clip)
    for i in range(5):
      xs, xf = self.slow[i](xs), self.fast[i](xf)
      if i < 4:
        xs = self.lat[i](xs, xf)             # Unidirectional, from Fast to Slow
    feat = torch.cat([self.pool(xs).flatten(1), self.pool(xf).flatten(1)], dim=1)
    return self.fc(self.dropout(feat))


model = SlowFast(num_classes=400)
model.eval()    # Disable dropout; BN uses learned statistics (use model.train() for training)
with torch.no_grad():
  print(model(torch.randn(1, 3, 64, 224, 224)).shape)   # torch.Size([1, 400])

FAQ

Q. SlowFast and Two-Stream ConvNets both have two streams; how do they differ?
A.

Two-Stream ConvNets process two different inputs, RGB and optical flow, with networks of the same shape and fuse them at the end. SlowFast looks at the same RGB clip at two frame rates. The Fast pathway is a lightweight network with 1/8 of the channels, uses no optical flow, passes information to Slow midway through lateral connections, and the whole network is trained jointly.

Q. Why is it fine for the Fast pathway to have fewer channels?
A.

Because the Slow pathway takes care of spatial information, that is, "what is in the scene". The Fast pathway only needs to capture motion, so it needs little capacity for fine shapes and colors. In the paper, making the Fast pathway's input grayscale barely changed accuracy (75.6% → 75.5%), and even with 1/32 of the channels it was 1.6 points better than the Slow-only model.

Q. What do $lpha$, $eta$, and $ au$ each control?
A.

τ\tau is how many frames apart the Slow pathway samples (typically 16), α\alpha is how many times more frames the Fast pathway sees than Slow (typically 8; Fast samples every τ/α=2\tau / \alpha = 2 frames), and β\beta is the ratio of the Fast pathway's channels to Slow's (typically 1/8). For β\beta, 1/6 and 1/8 were the best, and every value from 1/4 to 1/32 was better than Slow alone.

References

  1. Feichtenhofer, C., Fan, H., Malik, J., & He, K. (2019). SlowFast Networks for Video Recognition. ICCV 2019. arXiv:1812.03982.
  2. facebookresearch/SlowFast (official code by the authors).
  3. Carreira, J., & Zisserman, A. (2017). Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset. CVPR 2017. arXiv:1705.07750.
  4. Lin, J., Gan, C., & Han, S. (2019). TSM: Temporal Shift Module for Efficient Video Understanding. ICCV 2019. arXiv:1811.08383.