Skip to content
ml-recall

Topic notes

Landmark Architectures

The landmark CNNs (AlexNet, VGG, NiN, GoogLeNet, ResNet, DenseNet, MobileNet), the design idea each introduced, where their parameters sit, and a note on graph neural networks.

4-min read AI-checked

Practise 29 questions Take a test

Key ideas

Model (year) Key idea Parameters
AlexNet (2012) deep CNN on GPUs: ReLU, dropout, augmentation, 11×1111 \times 11 first conv 61.1 M
VGG-16 (2014) blocks of 3×33 \times 3 convs + 2×22 \times 2 max-pool, then 3 FC layers 138.4 M
NiN (2013) 1×11 \times 1 convs after each conv; global average pooling instead of FC layers –
GoogLeNet (2014) Inception block: parallel branches concatenated 6.6 M
ResNet-18 / 50 (2015) residual (identity shortcut) blocks with batch norm 11.7 M / 25.6 M
DenseNet-121 (2017) concatenate all earlier feature maps 8.0 M
MobileNet (2017) depthwise separable convolutions 4.2 M

Counts are for torchvision's ImageNet models (see the code below); MobileNet's is from its paper.

Formulas

conv weights=cocik2,stack of n layers 3×3: field (2n+1)2, 9nC2 weights\text{conv weights} = c_o c_i k^2,\qquad \text{stack of } n \text{ layers } 3 \times 3:\ \text{field } (2n + 1)^2,\ 9nC^2 \text{ weights} depthwise separable coststandard conv cost=k2ci+cicok2cico=1co+1k2\frac{\text{depthwise separable cost}}{\text{standard conv cost}} = \frac{k^2 c_i + c_i c_o}{k^2 c_i c_o} = \frac{1}{c_o} + \frac{1}{k^2} DenseNet block input to layer ℓ=c0+(ℓ−1) k,block output=c0+L k\text{DenseNet block input to layer } \ell = c_0 + (\ell - 1)\,k,\qquad \text{block output} = c_0 + L\,k

Worked example

torchvision's VGG-16 on a 224×224224 \times 224 image: the conv part outputs 512×7×7=25,088512 \times 7 \times 7 = 25{,}088 values. The first FC layer to 4096 units has 25,088⋅4096+4096=102,764,54425{,}088 \cdot 4096 + 4096 = 102{,}764{,}544 parameters, 74% of the network's 138,357,544138{,}357{,}544; the three FC layers together hold 89%. At 4 bytes per float32 the whole model is about 553 MB. Stacking three 3×33 \times 3 convs with C=256C = 256 uses 27⋅2562=1,769,47227 \cdot 256^2 = 1{,}769{,}472 weights, against 49⋅2562=3,211,26449 \cdot 256^2 = 3{,}211{,}264 for one 7×77 \times 7 conv with the same receptive field. A dense block with 64 input channels, 4 layers and growth rate 32 feeds its fourth layer 64+3⋅32=16064 + 3 \cdot 32 = 160 channels and outputs 192192.

In code

import torchvision.models as M
names = ["alexnet", "vgg16", "resnet18", "resnet50", "densenet121"]
counts = {n: sum(p.numel() for p in getattr(M, n)(weights=None).parameters()) for n in names}
print(counts)  # {'alexnet': 61100840, 'vgg16': 138357544, 'resnet18': 11689512, 'resnet50': 25557032, 'densenet121': 7978856}
vgg = M.vgg16(weights=None)                          # architecture only, no download
print(sum(p.numel() for p in vgg.classifier[0].parameters()))  # 102764544

Common pitfalls

References

  1. Dive into Deep Learning — Sec. 8.1.2 AlexNet (8.1.2.1 Architecture, 8.1.2.2 Activation Functions, 8.1.2.3 Capacity Control and Preprocessing), 8.1.4 Discussion
  2. Simonyan & Zisserman (2014), Very Deep Convolutional Networks for Large-Scale Image Recognition — Sec. 2.1 Architecture; 2.2 Configurations (Table 1); 2.3 Discussion; 4.1 Single Scale Evaluation
  3. Dive into Deep Learning — Sec. 8.3.1 NiN Blocks, 8.3.2 NiN Model, 8.3.4 Summary
  4. Dive into Deep Learning — Sec. 8.4.1 Inception Blocks, 8.4.2 GoogLeNet Model
  5. Dive into Deep Learning — Sec. 8.6.1 Function Classes, 8.6.2 Residual Blocks, 8.6.3 ResNet Model, 8.6.5 ResNeXt
  6. Dive into Deep Learning — Sec. 8.7.1 From ResNet to DenseNet, 8.7.2 Dense Blocks, 8.7.3 Transition Layers, 8.7.6 Summary and Discussion
  7. Howard et al. (2017), MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications — Sec. 3.1 Depthwise Separable Convolution; Table 4
  8. Xu et al. (2018), How Powerful are Graph Neural Networks? — Sec. 4 Building Powerful Graph Neural Networks (Lemma 2, Theorem 3), 4.1 Graph Isomorphism Network (Lemma 5)