Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A tiny network inside every pixel, and no big classifier
AlexNet and VGG end with huge fully connected layers that hold most of their weights and remember where things were in the training images. Network in Network did two things. After each convolution it adds 1 × 1 convolutions: a small neural network that looks at all the channels of one pixel and recombines them. At the end it makes one feature map per class and simply averages each map over the whole image to get that class’s score. No big classifier, far fewer weights, and the score no longer depends on where the object is.
| stage | output C × H × W | parameters | multiply–adds |
|---|---|---|---|
| mlpconv1 | 96 × 26 × 26 | 53.6 k | 155.36 M |
| mlpconv2 | 256 × 12 × 12 | 746.2 k | 503.94 M |
| mlpconv3 | 384 × 5 × 5 | 1.18 M | 169.87 M |
| mlpconv4 | 1000 × 1 × 1 | 5.46 M | 136.40 M |
| AlexNet | 61.10 M parameters | 714.19 M MACs |
| Network in Network | 7.44 M parameters | 965.57 M MACs |
1 × 1 convolutions and global average pooling are in GoogLeNet, ResNet, MobileNet and almost every network that runs on a robot or satellite, because they save parameters and let one network accept images of any size.
- 1. A 1 × 1 convolution combines…
- 2. Global average pooling gives each class…
- 3. NiN removes…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- 1 × 1 convolution:
- at each pixel, y = W x + b with W of size Cout × Cin;
- parameters Cin·Cout + Cout, so 96 → 96 has 9,312;
- two channels (a, b) mapped by rows (1, 1) and (1, −1) give (a + b, a − b).
- mlpconv block: a k × k convolution followed by two 1 × 1 convolutions, each with ReLU. On a 3-channel input with 96 channels and 11 × 11 kernels: 34,944 + 2·9,312 = 53,568 parameters.
- Global average pooling: a C × H × W map becomes C numbers, with no parameters.
- Heads on 512 × 7 × 7 maps with 1,000 classes:
- a fully connected head with one 4,096-unit hidden layer has 106,861,544 parameters;
- a 1 × 1 convolution to 1,000 maps plus global averaging has 513,000.
- 1. Parameters of a 1 × 1 conv 96 → 96 with bias:
- 2. GAP turns 512 × 7 × 7 into…
- 3. GAP's parameters:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.NiN in code
Exercise 1.
- An mlpconv block gave the same output at a pixel as the k × k convolution followed by two per-pixel matrix multiplications.
- Global average pooling was unchanged by a circular shift.
- The 1 × 1 + GAP head needed 513,000 parameters against 106.9 million for a fully connected head with one hidden layer.
Practice.
- A 1 × 1 convolution is
nn.Conv2d(c_in, c_out, 1), and global average pooling isnn.AdaptiveAvgPool2d(1). - Because the head has no fixed input size, the network accepts images of any size.
- The NiN paper used dropout between mlpconv blocks, with no fully connected layers, and reached 10.41% error on CIFAR-10 without augmentation (8.81% with).
- Global averaging also makes class activation maps possible (Zhou et al., 2016): the per-class maps before pooling show where each class is.
nin_block = lambda cin, c, k, s, p: nn.Sequential(nn.Conv2d(cin, c, k, s, p), nn.ReLU(),
nn.Conv2d(c, c, 1), nn.ReLU(), nn.Conv2d(c, c, 1), nn.ReLU())
head = nn.Sequential(nin_block(384, 10, 3, 1, 1), nn.AdaptiveAvgPool2d(1), nn.Flatten())- 1. PyTorch's global average pooling layer:
- 2. A GAP head lets the network accept…
- 3. Class activation maps use…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
mlpconv as a better local model. A convolution followed by ReLU is a generalised linear model of each patch, so it can only separate patterns that are linearly separable in the patch. Adding 1 × 1 layers makes the per-patch model a multilayer perceptron, which is a universal approximator. That is more abstraction per receptive field before the next layer combines neighbours.
1 × 1 convolutions as channel mixing.
- They change the number of channels cheaply. GoogLeNet and ResNet bottlenecks use them to reduce channels before expensive 3 × 3 or 5 × 5 convolutions.
- They are exactly a fully connected layer applied independently at every pixel.
Global average pooling as a structural regulariser.
- Each final map is forced to act as a confidence map for one class.
- The head has no parameters to overfit.
- The output is invariant to where features occur: translating the input translates the maps, and the average does not change, up to border effects.
A fully connected head instead learns one weight per position, so it must see each class at each position (exercise 2).
- 1. A conv + ReLU is, per patch, a…
- 2. A 1 × 1 convolution equals…
- 3. GAP is invariant to…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does global pooling generalise across positions?
History.
- M. Lin, Q. Chen and S. Yan (2014) introduced Network in Network.
- C. Szegedy et al. (2015) built GoogLeNet’s Inception modules on 1 × 1 reductions and ended it with global average pooling.
- B. Zhou et al. (2016) used global average pooling to produce class activation maps.
Exercise 2. A 5 × 5 convolution (16 maps) with ReLU is followed by one of two heads:
- 2 × 2 average pooling and a fully connected layer;
- a 1 × 1 convolution to 10 class maps and global averaging.
The network is trained on 300 digits whose left edge lies in columns 0 to 2 of a 12 × 12 canvas. It is tested on new digits in those columns and in columns 5 to 7, positions never seen in training. Results are the mean of 2 seeds:
| head | parameters | train | test, seen columns | test, unseen columns |
|---|---|---|---|---|
| pool + fully connected | 2,986 | 1.000 | 0.723 | 0.139 |
| 1 × 1 conv + global average | 586 | 0.913 | 0.802 | 0.320 |
- The fully connected head memorised positions. It fit the training set perfectly but was near chance (0.10) on unseen columns, because its weights for those positions were never trained.
- The global-average head did better everywhere with five times fewer parameters. It also fitted the training set less tightly (0.91), a sign of less overfitting. Seeds 2 to 4 agreed: unseen accuracy 0.16 to 0.32 against 0.09 to 0.13.
- Transfer was only partial. The convolution sees the canvas border differently at different positions, and averaging includes many background positions, so the class maps are not exactly shift-invariant. NiN’s claim holds in direction, not perfectly.
NiN ideas in AI, robotics and aerospace
- Efficient backbones: 1 × 1 bottlenecks are why MobileNets and EfficientNets fit on drones and phones.
- Any-size inputs: global pooling lets one network process satellite tiles or camera frames of different sizes.
- Localisation for free: class activation maps show where a classifier found an object, useful for weakly labelled aerial and medical images.
References
- M. Lin, Q. Chen, S. Yan (2014). “Network in network.” Proc. ICLR.
- C. Szegedy et al. (2015). “Going deeper with convolutions.” Proc. CVPR.
- B. Zhou, A. Khosla, A. Lapedriza, A. Oliva, A. Torralba (2016). “Learning deep features for discriminative localization.” Proc. CVPR.