Search

Search papers and lessons

Very Deep Convolutional Networks for Large-Scale Image Recognition (VGG)

Karen Simonyan, Andrew Zisserman · 2014

Simonyan and Zisserman fix every design choice of a convolutional network except depth, use only 3 by 3 filters, and show that going from 11 to 19 weight layers steadily cuts ImageNet error.

On this page

  • Colour = topic mix
  • Calculus
  • Architectures
  • Neural network basics
  • Linear algebra
  • Probability
  • Optimizers
  • Sign in to see your progress

TL;DR

Simonyan and Zisserman asked a narrow question: if you keep every design choice of a convolutional network fixed and change only its depth, how much does depth help image classification? They built a family of networks that use only 3 by 3 filters and range from 11 to 19 weight layers. The deeper nets were more accurate on ImageNet, and the team placed second in the 2014 ILSVRC classification task and first in localisation.

Where you'll see it: the VGG-16 and VGG-19 networks used as feature extractors, and as perceptual-loss networks in image generation.

The problem

By 2014, convolutional networks had won the ImageNet classification challenge twice in a row. Each winning network had changed many things at once. AlexNet used large first-layer filters, 11 by 11 with stride 4. The ILSVRC-2013 entries used 7 by 7 filters with stride 2, and they also changed how the network was run over an image. Because so much changed between entries, nobody could say how much of the gain came from depth.

Depth was also hard to use. Deep plain networks are unstable to train. Gradients can shrink or blow up as they pass back through many layers, and the choice of initial weights decides whether learning starts at all. A method that trains deeper networks reliably was needed before depth could be studied fairly.

Key idea

Keep the architecture simple and identical across all the networks. Every convolution uses a 3 by 3 filter with stride 1 and padding 1, so it keeps the height and width. Max pooling with a 2 by 2 window and stride 2 halves the grid after some of the convolutions. Depth is then just the number of times the block repeats.

The reason 3 by 3 filters are enough is that stacking them grows the view. Two layers see a 5 by 5 region of the input and three see a 7 by 7 region. Each extra layer also adds a ReLU non-linearity. A stack of three 3 by 3 layers therefore covers the same area as one 7 by 7 layer, with more non-linear steps and fewer weights.

flowchart LR
    A[one 7 x 7 layer: 49 C squared weights] --> X[same 7 x 7 view]
    B[three 3 x 3 layers: 27 C squared weights] --> X
    B --> N[three ReLU steps instead of one]

The paper states the comparison directly. If the stack and the single layer both have CC channels in and out, the stack has 3⋅32C2=27C23 \cdot 3^2 C^2 = 27C^2 weights and the single layer has 72C2=49C27^2 C^2 = 49C^2. The single layer needs 81 percent more weights. The authors read the small filters as a regulariser: they force the large filter to factor into smaller ones with non-linearities between them.

The method

Architecture

The input is a fixed 224×224224 \times 224 RGB image. The only preprocessing is subtracting the mean RGB value, computed on the training set, from each pixel. The image then passes through a stack of convolutional layers, followed by three fully connected layers with 4096, 4096 and 1000 channels. The 1000 channels correspond to the ILSVRC classes, and a softmax produces the final probabilities. All hidden layers use ReLU. Except for one configuration, the networks do not use local response normalisation, because the authors found it did not help and it added memory and compute.

The configurations, called A to E in Table 1 of the paper, differ only in depth. Network A has 11 weight layers: 8 convolutional and 3 fully connected. Network E has 19: 16 convolutional and 3 fully connected. The first convolutional layer has 64 channels. The channel count doubles after each pooling step until it reaches 512. Configuration C adds three 1×11 \times 1 convolutions, and configuration D is the same as C but uses 3×33 \times 3 filters in those three places.

The paper also reports the parameter counts:

ConfigurationA, A-LRNBCDE
Weight layers1113161619
Parameters (millions)133133134138144

Depth adds only a little to the total because most parameters sit in the first fully connected layer, which maps the final 7×7×5127 \times 7 \times 512 feature map to 4096 values.

Training

Training minimises the multinomial logistic regression objective, which is the cross-entropy of the softmax outputs. The optimiser is mini-batch gradient descent with Momentum 0.9 and batch size 256. The training is regularised with an L2 penalty multiplier of 5⋅10−45 \cdot 10^{-4}, which is weight decay, and with Dropout at ratio 0.5 on the first two fully connected layers.

The learning rate starts at 10−210^{-2}. It is divided by 10 when validation accuracy stops improving, which happened three times. Training stops after 370,000 iterations, which the paper reports as 74 epochs.

Initialisation is handled in two steps. The authors first trained the shallow configuration A from random weights, drawn from a zero-mean normal distribution with variance 10−210^{-2} and zero biases. For deeper networks they copied the first four convolutional layers and the last three fully connected layers from the trained A, and initialised the middle layers randomly. They did not lower the learning rate for the copied layers. The paper notes that a later version of the work found the random initialisation of Glorot and Bengio, which is Xavier initialisation, made the pretraining step unnecessary.

Each training image is rescaled so that its smaller side is SS, and a 224×224224 \times 224 crop is taken at random. Crops are randomly flipped horizontally and given a random RGB colour shift. The paper uses two ways to choose SS. Single-scale training fixes SS at 256 or 384. Multi-scale training draws SS uniformly from [256,512][256, 512], which the authors describe as scale jittering. For speed, the multi-scale models were fine-tuned from a single-scale model trained at S=384S = 384.

Testing

At test time an image is rescaled so that its smaller side is QQ, which need not equal SS. The fully connected layers are rewritten as convolutions. The first becomes a 7×77 \times 7 convolution and the last two become 1×11 \times 1 convolutions. The resulting network runs over the whole image in one pass and produces a grid of class scores. The grid is averaged spatially to give one score per class. The softmax outputs for the image and its horizontal flip are then averaged.

The authors contrast this with the crop-based testing of earlier work. Running on a single full image avoids recomputing the network for each crop. As a reference point the paper also evaluates 50 crops per scale, a 5 by 5 grid with flips, for 150 crops over 3 scales. It finds the two approaches complementary: combining dense and multi-crop evaluation beats either alone.

Implementation

The code was based on the public C++ Caffe toolbox with changes for several GPUs and for training on uncropped images at several scales. Each batch is split across GPUs, the gradients are averaged, and the result matches single-GPU training exactly. The authors report a 3.75 times speedup on a 4-GPU machine. On four NVIDIA Titan Black cards, training one network took 2 to 3 weeks depending on the architecture.

Results

The main benchmark is ILSVRC-2012, with 1.3 million training images, 50,000 validation images and 100,000 test images with hidden labels. Most experiments report error on the validation set. Table 3 shows the single-scale results, with top-1 and top-5 validation error in percent.

ConfigTrain STest QTop-1 valTop-5 val
A25625629.610.4
A-LRN25625629.710.5
B25625628.79.9
C25625628.19.4
C38438428.19.3
C[256, 512]38427.38.8
D25625627.08.8
D38438426.88.7
D[256, 512]38425.68.1
E25625627.39.0
E38438426.98.7
E[256, 512]38425.58.0

Three findings stand out. Local response normalisation did not help (A-LRN is no better than A). Error fell as depth grew from 11 to 19 layers, and the paper says it saturated at 19 layers on this dataset. Scale jittering in training beat fixed-scale training, even when the test scale was fixed. The authors also trained a shallow net with five 5×55 \times 5 convolutions, derived from B by merging each pair of 3×33 \times 3 layers. Its top-1 error was 7 percent higher than B's, which the paper cites as evidence that small filters in a deep stack beat large filters in a shallow one.

Configuration C, which adds 1×11 \times 1 layers, does worse than D, which uses 3×33 \times 3 layers in the same positions. The authors read this as showing that the extra non-linearity helps (C beats B) but that spatial context from larger receptive fields matters more (D beats C).

Table 4 evaluates the models at several test scales, averaging the class posteriors across them. The best single-network validation error is 24.8 percent top-1 and 7.5 percent top-5, reached by D and E with multi-scale training. Table 5 compares dense and multi-crop evaluation for D and E. Combining both gives 24.4 percent top-1 and 7.1 percent top-5 for E.

For the competition, the authors combined several models by averaging their softmax outputs. The ILSVRC-2014 submission used an ensemble of 7 networks and reached 7.3 percent top-5 test error. After the submission the authors combined only the two best multi-scale models, D and E, and reached 6.8 percent top-5 test error with dense and multi-crop evaluation. The paper says its best single network reaches 7.0 percent top-5 test error, outperforming a single GoogLeNet by 0.9 percent. The GoogLeNet ensemble of 7 networks had 6.7 percent, which is slightly better than VGG's two-model ensemble.

The paper also reports the localisation task of ILSVRC-2014. Here the network regresses a bounding box instead of class scores, trained with a Euclidean loss. Per-class regression with all layers fine-tuned worked best. The paper reports 25.3 percent top-5 localisation error on the test set and says this won the 2014 localisation track.

Generalisation to other datasets

Appendix B freezes the ImageNet-trained networks and uses the 4096-dimensional activations of the penultimate layer as image features. The features are averaged over flips and over several scales, and an L2-normalised descriptor is classified with a linear SVM. The paper reports 89.7 percent mean average precision on PASCAL VOC-2007 for the combination of Net-D and Net-E, and 89.3 percent on VOC-2012. On Caltech-101 the mean class recall is 92.7 percent and on Caltech-256 it is 86.2 percent. The paper also reports 79.2 percent mean average precision on VOC-2012 action classification from the image alone, and 84.0 percent when the person's bounding box is also used.

Why it mattered

The paper turned depth into a clean experimental variable. Its message is that a conventional architecture, pushed deeper with small filters, is enough to reach state-of-the-art accuracy. The authors say they did not depart from the classical ConvNet design of LeCun et al. but improved it by increasing depth.

The released models mattered as much as the results. Researchers used the pretrained networks as fixed feature extractors and as starting points for fine-tuning. The paper (in a later revision) points to uses that followed in object detection, where Girshick et al. replaced the earlier ImageNet network with the 16-layer model, and to similar gains over the shallower AlexNet-style network in semantic segmentation, image caption generation, and texture and material recognition.

The paper also left an open problem. The depth gains saturated at 19 layers on ImageNet, and very deep plain stacks are hard to train. Residual connections, introduced in ResNet, were a later way to train much deeper networks.

Reading guide

Read the paper in this order and use these lessons for the prerequisites in each part.

Check yourself

QuestionRecall: what are the filter size, stride and padding of every convolution in the VGG configurations?Show answer

Every convolution uses a 3 by 3 filter with stride 1 and padding 1. The padding keeps the height and width unchanged, so only the five max-pooling steps change the grid size, from 224 down to 7.

QuestionComputation: for a layer with 256 input and 256 output channels, how many weights does one 7 by 7 convolution have, and how many does a stack of three 3 by 3 convolutions with the same channel counts have? Ignore biases.Show answer

One 7 by 7 layer has 49⋅2562=49⋅65,536=3,211,26449 \cdot 256^2 = 49 \cdot 65{,}536 = 3{,}211{,}264 weights. Three 3 by 3 layers have 3⋅9⋅65,536=1,769,4723 \cdot 9 \cdot 65{,}536 = 1{,}769{,}472 weights. The single layer needs about 81 percent more, as the paper states.

QuestionWhy: the paper finds that configuration C, with extra 1 by 1 layers, is worse than configuration D with 3 by 3 layers, even though both have 16 layers. What does this say about what matters?Show answer

C has more non-linearity than B, and it beats B. But D beats C, and the difference is that D's extra layers have 3 by 3 filters, which see spatial context. The paper concludes that adding non-linearity helps, but capturing spatial context with non-trivial receptive fields matters more.

QuestionApplied: you have a small dataset of 2,000 images in 5 classes and want to use a VGG-style network. Should you train from scratch or use the ImageNet-trained convolutional layers as fixed features, and why?Show answer

Use the ImageNet-trained convolutional layers as fixed feature extractors and train a linear classifier on top. Training 130 million or more weights from scratch on 2,000 images would overfit badly. The paper's Appendix B does exactly this on Caltech and VOC, keeping the pretrained weights fixed and training an SVM on the 4096-dimensional features.

Sources

Read the full paper

Karen Simonyan, Andrew Zisserman, 2014. arXiv:1409.1556