AI Logic

Architectures

C3D

Updated:

The architecture of C3D. On the left, the difference between 2D and 3D convolution (2D convolution on an image or on stacked frames outputs a single image, whereas 3D convolution on a video volume keeps the temporal ordering). On the right, the overall C3D network (a 16-frame clip passes through eight 3×3×3 3D convolution layers and five 3D pooling layers, followed by two fully connected layers and a softmax for classification)

Background and Overview

C3D (Convolutional 3D) is a network that stacks eight layers of 3D convolution, which convolves along time as well as height and width, to learn appearance and motion jointly from short video clips. It was presented at ICCV 2015 by Tran et al. from Facebook AI Research and Dartmouth College. The main focus of the paper is to use the intermediate outputs of the trained network as general-purpose features (video descriptors) that work across a variety of video tasks.

In image classification, the outputs of the fully connected layers of a CNN trained on ImageNet were widely used as features for other tasks. However, image CNNs cannot represent motion. Even when frames are stacked and fed into 2D convolution, as in Two-Stream ConvNets, the temporal ordering is summed away in the first layer.

C3D addressed this in two ways.

  • Preserve the temporal ordering in every layer: the network is built only from 3D convolutions and 3D pooling, carrying temporal information into deep layers.
  • Use 3 × 3 × 3 kernels throughout: comparing different temporal kernel sizes, the authors found that setting it to 3 in every layer works best.

The main results of the paper are as follows.

  • Simply combining C3D features trained on 1.1 million sports videos (Sports-1M) with a linear SVM outperformed the previous best results on 4 of 6 benchmarks covering action recognition, action similarity labeling, scene recognition, and object recognition.
  • On UCF-101, it reached 85.2% (concatenating features from three networks), the highest among methods using RGB only.
  • The features are compact yet strong: even reduced to 10 dimensions with PCA, they achieved 52.8% on UCF-101.

C3D became a starting point for later 3D CNNs (such as I3D and SlowFast), and is also used as a baseline in the Kinetics paper.

Theory: Processing Whole Clips with 3D Convolution

The difference between 2D and 3D convolution

The left side of the figure at the top of this article corresponds to the comparison in Figure 1 of the paper. A video clip is represented as c×l×h×wc \times l \times h \times w (channels, number of frames, height, width), and a 3D kernel size is written as d×k×kd \times k \times k (where dd is the temporal size).

Input and operationOutputTemporal information
2D convolution on a single imageImage (2D)Never present
2D convolution with ll frames as channelsImage (2D)Summed away in the first layer
3D convolution on a clip (d<ld < l)Volume (3D)Preserved, since the kernel also slides along time

The value of a 3D convolution output at position (t,y,x)(t, y, x) is a weighted sum that also includes nearby frames along time (WW is the kernel and bb is the bias).

Y(t,y,x)=∑c∑i=0d−1∑j=0k−1∑m=0k−1Wc(i,j,m) Xc(t+i,y+j,x+m)+bY(t, y, x) = \sum_{c} \sum_{i=0}^{d-1} \sum_{j=0}^{k-1} \sum_{m=0}^{k-1} W_c(i, j, m) \, X_c(t+i, y+j, x+m) + b

Pooling works the same way: 3D max pooling takes the maximum over nearby values along time as well.

The C3D network (Figure 3 and Section 3.3 of the paper)

C3D consists of 8 3D convolution layers, 5 3D max-pooling layers, 2 fully connected layers, and a softmax output layer (right side of the figure at the top of this article).

  1. Input: frames are resized to 128 × 171, and a random 16 × 112 × 112 crop is taken from a 16-frame clip (3×16×112×1123 \times 16 \times 112 \times 112).
  2. 3D convolution: all 3 × 3 × 3 with stride 1. The number of filters is 64 for Conv1a, 128 for Conv2a, 256 for Conv3a and 3b, and 512 for Conv4a, 4b, Conv5a, and 5b.
  3. 3D pooling: only Pool1 is 1 × 2 × 2 (no temporal reduction); the others are 2 × 2 × 2 with stride 2. This avoids merging the temporal signal too early; the 16-frame clip is halved to 8, 4, 2, and 1 through Pool2 to Pool5.
  4. Fully connected layers: fc6 and fc7 have 4096 units, and a final softmax outputs the class.

Training (Section 3.3)

  • The network is trained from scratch on the training split of Sports-1M (487 sports, 1.1 million videos).
  • Five 2-second clips are randomly extracted from each video, randomly cropped to 16 × 112 × 112, and horizontally flipped with 50% probability.
  • SGD with a mini-batch size of 30 is used, starting with a learning rate of 0.003 that is halved every 150k iterations, and training stops at 1.9 million iterations (about 13 epochs).

Use as features (Section 3.3)

  1. The video is split into 16-frame clips with an 8-frame overlap.
  2. Each clip is passed through C3D, and the fc6 output (4096 dimensions) is taken.
  3. The fc6 outputs of all clips in the video are averaged and L2-normalized. This is the C3D feature (video descriptor).

The resulting features can be used for tasks such as action recognition simply by attaching a linear SVM. The network itself is not fine-tuned for each task.

Why 3 × 3 × 3 Kernels Work Well

Experiments comparing temporal kernel sizes (Section 3.2)

Using a network with five 3D convolution layers, the paper fixed the spatial size at 3 × 3 and varied only the temporal size dd, comparing on UCF-101.

  • The same dd in every layer: four settings, d=1,3,5,7d = 1, 3, 5, 7. d=1d = 1 is equivalent to frame-wise 2D convolution.
  • Varying across layers: increasing from shallow to deep as 3-3-5-5-7, and decreasing as 7-5-5-3-3.

The result was that d=3d = 3 in every layer performs best, and d=1d = 1 (2D convolution) is clearly worse. The paper attributes the weakness of d=1d = 1 to its inability to model motion. The difference in parameter count is at most 51 thousand (less than 0.3% of the total 17.5 million), so the gap comes from how time is handled, not from network size. The same trend held when the spatial kernel was changed to 5 × 5 or when the input was kept at its original size (240 × 320).

The idea of stacking small kernels deeply also matches the finding of VGG in 2D image CNNs. By stacking many 3 × 3 × 3 layers, each layer's view is narrow, yet deep layers can see a wide span of time and space together.

What C3D attends to

The paper visualized the features with the strongest responses in Conv5b by projecting them back to the input image space. C3D focuses on the appearance of people and objects in the first few frames, and then tracks salient motion in the following frames. For example, in a pole vault video, it first captures the whole person and then follows the jumping motion.

As an everyday analogy, 2D convolution is like a person looking at photos one at a time, while 3D convolution is like a person flipping through a flip book a few pages at a time. Even though each flip covers only a short span (3 frames), repeating it many times captures the flow of long motions.

C3D features improve further when combined with improved dense trajectories (iDT) (85.2% → 90.4% on UCF-101). The paper explains that iDT, built from optical flow tracking and low-level gradient histograms, complements C3D, which captures high-level semantics. In contrast, combining with ImageNet features adds only 0.6 points, suggesting that C3D already carries appearance information.

Experimental Results

Classification on Sports-1M (Table 2 of the paper)

MethodNumber of networksClip hit@1Video hit@1Video hit@5
DeepVideo (single frame + multi-resolution)342.460.078.5
DeepVideo (Slow Fusion)141.960.980.2
Convolution pooling on 120-frame clips370.872.490.8
C3D (trained from scratch)144.960.084.4
C3D (pre-trained on the internal I380K dataset, then fine-tuned)146.161.185.2

C3D outperforms DeepVideo, which also uses short clips, by about 5 points on video hit@5. It does not reach the method using long 120-frame clips, but the paper notes that the two are not directly comparable because the input lengths differ.

Action recognition on UCF-101 (average over 3 splits; Table 3 of the paper; C3D uses a linear SVM)

InputMethodAccuracy (%)
Simple featuresImageNet features + linear SVM68.8
Simple featuresiDT (Bag of Words) + linear SVM76.2
RGB onlyDeepVideo65.4
RGB onlySpatial stream (Two-Stream)72.6
RGB onlyLRCN71.1
RGB onlyComposite LSTM model75.8
RGB onlyC3D (1 network)82.3
RGB onlyC3D (3 networks)85.2
Multiple featuresiDT + Fisher vectors87.9
Multiple featuresTwo-Stream88.0
Multiple featuresLSTM on long clips88.6
Multiple featuresMulti-skip feature stacking89.1
Multiple featuresC3D (3 networks) + iDT90.4

"3 networks" means concatenating the features of three networks (12,288 dimensions): one trained on I380K, one trained on Sports-1M, and one trained on I380K and fine-tuned on Sports-1M.

Other tasks (Tables 1, 4, and 5 of the paper)

TaskDatasetPrevious bestC3D
Action similarity labeling (accuracy)ASLAN68.778.3
Scene recognitionYUPENN96.298.1
Scene recognitionMaryland77.787.7
Object recognitionEgocentric videos of everyday objects12.022.3

Computational speed (time to extract features from all of UCF-101; Table 6 of the paper)

MethodDeviceFrames per secondCompared with C3D
iDTCPU3.591.4× slower
Brox optical flowCPU0.31135.9× slower
Brox optical flowGPU1.2274.6× slower
C3DGPU313.91

Since no optical flow is needed, features can be extracted much faster than real time.

Practical Considerations

Keep the following points in mind when using C3D.

  • It sees 16 frames at a time: each clip is 16 frames, and longer temporal relationships can only be handled by averaging clip features. It is not suited to tasks where the order of actions within a video matters.
  • The input resolution is low: to keep computation down, frames are resized to 128 × 171 and cropped to 112 × 112. In the paper, C3D loses to ImageNet features, which use full-size images, by 3.4 points on object recognition, and the low resolution is cited as the reason.
  • Most parameters are in the fully connected layers: even in the 5-layer network used for the paper's search, most of the 17.5 million parameters are in the fully connected layers. The reimplementation in the I3D paper (a 3D ConvNet close to C3D) has 79 million parameters.

C3D cannot use ImageNet pre-trained weights and must be trained from scratch on a large amount of video. This is because 3D kernels differ in shape from those of 2D image CNNs. The paper trained on Sports-1M (1.1 million videos), but when the I3D paper trained a C3D-like model from scratch on Kinetics, it reached only 56.1% top-1, far behind I3D (71.1% with RGB), which inflates ImageNet weights to 3D. When training a 3D CNN on small data, consider reusing 2D pre-trained weights as I3D does.

Comparison with Other Models

Comparing video action recognition models from the same perspective gives the following.

ModelConvolutionHandling of timeFrames seen at onceOptical flowPre-training
Two-Stream ConvNets2DA separate CNN sees stacked flow input1 RGB frame + 10 flow pairsRequiredSpatial: ImageNet
C3D3D (all 3×3×3)Convolves along time in every layer16Not neededSports-1M (from scratch)
TSN2DConsensus over snippets sparsely sampled from the whole video1 snippet per segmentUsed (RGB only also possible)ImageNet
I3D3D (inflated from 2D)Inflates Inception-v1 kernels along time64Used (RGB only also possible)ImageNet + Kinetics
TSM2DShifts part of the channels along time8–16Not neededImageNet
SlowFast3D (partly 2D)Two pathways at different frame rates4 + 32 (64-frame window)Not neededNone (from scratch)

Rough guidelines for choosing:

  • Learning the basics of 3D convolution or getting simple video features: C3D is the starting point. Extracting fc6 features and attaching a linear classifier works for a wide range of tasks.
  • Prioritizing accuracy: I3D, which can reuse ImageNet weights and is pre-trained on Kinetics, and SlowFast achieve higher accuracy.
  • Keeping computation light: TSM, which mixes temporal information without 3D convolution, fits.

PyTorch example

Show code
python
import torch
import torch.nn as nn

"""
Example implementation of C3D (Tran et al. 2015, Figure 3 and Section 3.3)
Input: a 16-frame clip (N, 3, 16, 112, 112)  ← (N, channels, time, height, width)
"""


def conv3d(cin, cout):
  # Every 3D convolution is 3×3×3 with stride 1. Padding 1 keeps the size
  return nn.Sequential(nn.Conv3d(cin, cout, kernel_size=3, padding=1), nn.ReLU(inplace=True))


class C3D(nn.Module):
  def __init__(self, num_classes=487, p_drop=0.5):
    super().__init__()
    self.features = nn.Sequential(
      conv3d(3, 64),                                          # Conv1a
      nn.MaxPool3d(kernel_size=(1, 2, 2), stride=(1, 2, 2)),  # Pool1: no temporal reduction
      conv3d(64, 128),                                        # Conv2a
      nn.MaxPool3d(2, stride=2),                              # Pool2: time 16 → 8
      conv3d(128, 256), conv3d(256, 256),                     # Conv3a, 3b
      nn.MaxPool3d(2, stride=2),                              # Pool3: time 8 → 4
      conv3d(256, 512), conv3d(512, 512),                     # Conv4a, 4b
      nn.MaxPool3d(2, stride=2),                              # Pool4: time 4 → 2
      conv3d(512, 512), conv3d(512, 512),                     # Conv5a, 5b
      nn.MaxPool3d(2, stride=2),                              # Pool5: time 2 → 1
    )
    # The paper does not state the input size of fc6 or the dropout rate, so
    # the input size is determined by LazyLinear and dropout is set to the common 0.5
    self.fc6 = nn.Sequential(nn.Flatten(), nn.LazyLinear(4096), nn.ReLU(inplace=True), nn.Dropout(p_drop))
    self.fc7 = nn.Sequential(nn.Linear(4096, 4096), nn.ReLU(inplace=True), nn.Dropout(p_drop))
    self.out = nn.Linear(4096, num_classes)

  def forward(self, clip):
    return self.out(self.fc7(self.fc6(self.features(clip))))  # scores before softmax

  @torch.no_grad()
  def video_descriptor(self, clips):
    """Section 3.3: from 16-frame clips with an 8-frame overlap (K, 3, 16, 112, 112),
    take the fc6 outputs, average them, and return an L2-normalized 4096-dim feature."""
    self.eval()   # disable dropout
    f = self.fc6(self.features(clips)).mean(dim=0)
    return f / f.norm()


model = C3D(num_classes=101)
model.eval()
clips = torch.randn(4, 3, 16, 112, 112)
print(model(clips).shape)                     # torch.Size([4, 101])
print(model.video_descriptor(clips).shape)    # torch.Size([4096])

FAQ

Q. How does C3D differ from stacking frames and feeding them to a 2D CNN?
A.

When frames are stacked as channels and fed to 2D convolution, all frames are summed with weights in the first layer, and the output is a single image. The temporal ordering is lost at that point. C3D's 3D convolution also slides the kernel along time, so its output keeps a temporal ordering as well. Stacking eight such layers gradually integrates appearance and motion layer by layer.

Q. How are C3D features computed?
A.

The video is split into 16-frame clips with an 8-frame overlap, each clip is passed through C3D, and the fc6 output (4096 dimensions) is taken. The outputs of all clips in the video are averaged and L2-normalized to give the C3D feature. In the paper, simply attaching a linear SVM to it achieved 82.3% (one network) on UCF-101 action recognition.

Q. C3D and I3D are both 3D CNNs. What is the difference?
A.

C3D is a custom-designed 3D CNN trained from scratch on Sports-1M. I3D inflates the 2D kernels of Inception-v1, a proven image classification network, along time to make them 3D, and also reuses weights trained on ImageNet. I3D is deeper, sees 64 frames, and is pre-trained on Kinetics. In the I3D paper, it outperformed a C3D-like model.

References

  1. Tran, D., Bourdev, L., Fergus, R., Torresani, L., & Paluri, M. (2015). Learning Spatiotemporal Features with 3D Convolutional Networks. ICCV 2015. arXiv:1412.0767.
  2. Carreira, J., & Zisserman, A. (2017). Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset. CVPR 2017. arXiv:1705.07750.
  3. Simonyan, K., & Zisserman, A. (2014). Two-Stream Convolutional Networks for Action Recognition in Videos. NIPS 2014. arXiv:1406.2199.