Back to paper library
Paper notesarXiv 2013ICLR 2014

NiN

Foreshadowing the 1×1

Original paper

Network In Network

Paper authors

Min Lin · Qiang Chen · Shuicheng Yan

Publication
ICLR 2014Conference
First submitted to arXiv
arXiv:1312.4400
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{classiccnnsnin2013,
  title = {{Network In Network}},
  author = {Min Lin and Qiang Chen and Shuicheng Yan},
  year = {2013},
  eprint = {1312.4400},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1312.4400}
}
On this page

In the 2013 ImageNet classification challenge, the team from the National University of Singapore took second place. Its members included Min Lin and Qiang Chen.

In December that year, the two of them, together with Shuicheng Yan, released this paper. The paper itself has no ImageNet experiments and compares only on small datasets such as CIFAR, SVHN, and MNIST. Yet the 1×11\times1 convolutions and global average pooling it left behind turned up all over convolutional networks in the years that followed.

Both components grew out of the same question. Could the filters in a convolutional network be too simple?

Defining the Problem

First, look at what an ordinary convolutional layer does. Taking ReLU as an example, the output of the kk-th feature map at position (i,j)(i, j) is:

fi,j,k=max⁡(wkTxi,j, 0)f_{i,j,k} = \max(w_k^T x_{i,j},\ 0)

xi,jx_{i,j} is the input patch centered at (i,j)(i, j), and wkw_k is the kk-th filter. In other words, each filter takes one linear inner product with the patch and then applies ReLU once. The authors call this a generalized linear model (GLM).

There's only so much a linear model can separate. Suppose a filter is meant to detect “diagonal edges,” and the appearances of diagonal edges under different lighting and thicknesses happen to all fall on the same side of one hyperplane; then a single filter is enough. But the many appearances of one concept are often spread over a curved manifold, and one hyperplane can't cut them out cleanly.

How does an ordinary convolutional network cope? It adds more filters, each responsible for one appearance. The authors point out that this pushes the burden onto the next layer, which has to consider combinations of all the appearances from the layer below before it can piece together higher-level concepts.

The maxout network, published shortly before, took a step forward. It takes the maximum across several affine feature maps:

fi,j,k=max⁡m (wkmTxi,j)f_{i,j,k} = \max_m\,(w_{k_m}^T x_{i,j})

Taking the maximum of several linear functions gives a piecewise linear convex function, so it can separate concepts that lie within convex sets. But the authors consider “concepts lie within convex sets” to be an assumption that still may not hold.

So could we place, on each local patch, a model that makes no such assumption and can approximate general functions?

There's another problem at the end of a convolutional network. The last few layers are usually fully connected, and the authors see them as something of a black box: it's hard to say how category information gets passed back to the convolutional layers. Fully connected layers also overfit easily and have to be propped up by dropout.

Solving the Problem

Running a Small MLP on Every Patch

The authors' answer is to replace the linear filter with a small multilayer perceptron (MLP), which likewise slides over every position of the input, with all positions sharing the same weights. This kind of layer is called mlpconv:

Two diagrams side by side. (a) Linear convolution layer: a local patch of the input passes through one linear filter to produce one point on the output feature map. (b) mlpconv layer: the same local patch first passes through a small two-layer fully connected network, then produces one point on the output
Figure 1 from the paper, excerpted from page 2 of the v3 PDF. (a) A linear convolution layer; (b) an mlpconv layer, which adds a small MLP over the patch.

With an nn-layer MLP, mlpconv computes:

fi,j,k11=max⁡(wk11Txi,j+bk1, 0)  ⋮fi,j,knn=max⁡(wknnTfi,jn−1+bkn, 0)\begin{aligned} f^{1}_{i,j,k_1} &= \max\left({w^{1}_{k_1}}^T x_{i,j} + b_{k_1},\ 0\right) \\ &\ \ \vdots \\ f^{n}_{i,j,k_n} &= \max\left({w^{n}_{k_n}}^T f^{n-1}_{i,j} + b_{k_n},\ 0\right) \end{aligned}

The first line is exactly the same as an ordinary convolution, taking an inner product with the whole patch xi,jx_{i,j}. From the second line on, the input becomes the previous layer's output at the same position (i,j)(i, j), fi,jn−1f^{n-1}_{i,j}; in other words, only the values of all channels at this one position.

Looking at a single position and taking a weighted combination of all its channels is exactly what a 1×11\times1 convolution does. The authors state directly that mlpconv is equivalent to one ordinary convolutional layer followed by several 1×11\times1 convolutional layers.

The two views compute exactly the same thing. Sliding a small MLP over every patch is closer to the authors' idea: at every position, a small network judges whether a certain concept is present. A 3×33\times3 convolution followed by 1×11\times1 convolutions is how it is implemented: the 3×33\times3 convolution looks at the whole patch, and the 1×11\times1 convolutions after it only mix channels at each position. The authors also describe it from the channel side: every 1×11\times1 convolution layer is a “cross-channel parametric pooling” that reweights and recombines the previous layer's feature maps, then applies ReLU, layer after layer.

Compared with maxout, the difference is that maxout can only approximate convex functions, while the MLP in mlpconv is a universal function approximator that can handle concept distributions of many more shapes. The authors' reason for choosing an MLP over another universal approximator, the radial basis network, is also practical, since an MLP can be trained by backpropagation together with the convolutional network and can itself be made deep.

Replacing the Fully Connected Layers with an Average

The second component deals with the end of the network.

An ordinary convolutional network flattens the feature maps of the last convolutional layer, feeds them into a few fully connected layers, and then into a softmax. NiN instead has the last mlpconv layer output exactly as many feature maps as there are classes, averages each feature map over space, and feeds the resulting vector straight into the softmax. This is called global average pooling (GAP).

Take CIFAR-10: with 10 classes, the last layer outputs 10 feature maps, and GAP itself has no parameters at all; if those were 8×88\times8 maps fed into a fully connected layer for the 10 classes, it would need 6,410 parameters. For a small network the gap doesn't look large, but with AlexNet it becomes obvious. Its last three fully connected layers (9216→4096→4096→10009216\to4096\to4096\to1000) have 9216×4096+4096×4096+4096×1000=58,621,9529216\times4096+4096\times4096+4096\times1000 = 58{,}621{,}952 weights alone.

The authors list three advantages of GAP:

  1. No parameters, so this layer itself can't overfit.
  2. Each feature map corresponds to one class and can be read directly as that class's confidence map, which is easier to interpret than fully connected layers.
  3. Spatial information is summed out, making it less sensitive to translations of the input.

For point 2 to hold, the last layer has to actually be able to learn a feature map that stands for “cat.” The authors argue this relies on the stronger local modeling of mlpconv; with ordinary linear convolutions, the requirement may be too strict. We'll see this in the experiments later.

The Whole Network

The overall NiN architecture: three mlpconv layers in sequence, each containing a small multilayer perceptron; the feature maps of the last layer go through global average pooling and connect to the output class nodes
Figure 2 from the paper, excerpted from page 4 of the v3 PDF. Every NiN in the paper's experiments has three mlpconv layers plus a global average pooling layer.

The NiN used in the paper's experiments stacks three mlpconv layers, each containing a three-layer perceptron, and ends with global average pooling. Each mlpconv layer is followed by max pooling with stride 2; dropout is applied to the output of every mlpconv layer except the last, with weight decay on top. The authors put the detailed per-layer settings in the supplementary materials.

Discussion

The authors evaluate on the four datasets CIFAR-10, CIFAR-100, SVHN, and MNIST. Data preprocessing and the training/validation splits all follow the maxout paper; the implementation uses Alex Krizhevsky's cuda-convnet.

CIFAR-10 and CIFAR-100

CIFAR-10 has 10 classes of 32×3232\times32 color images, 50,000 for training and 10,000 for testing. The authors give each mlpconv layer the same number of feature maps as the maxout network, and tune only two hyperparameters, the local receptive field size and weight decay, on the validation set.

Table: Excerpted from Table 1 of the paper. Data augmentation means translation and horizontal flipping.
MethodTest error
Conv. maxout + Dropout11.68%
NIN + Dropout10.41%
Conv. maxout + Dropout + data augmentation9.38%
DropConnect + 12 networks + data augmentation9.32%
NIN + Dropout + data augmentation8.81%

Without data augmentation, NIN beats maxout by 1.27 percentage points; with translation and horizontal flipping, its 8.81% is also lower than DropConnect with 12 networks.

Dropout makes a real difference. The authors compare mlpconv layers with and without dropout between them. Without dropout, test error is 14.51%; with it, error falls to 10.41%, which the authors describe as a relative reduction of more than 20%.

CIFAR-100 has the same image format but 100 classes, with only a tenth as many images per class as CIFAR-10. The authors don't tune any hyperparameters for it; they just change the last layer to output 100 feature maps. Test error is 35.68%, more than one percentage point below the best result at the time without data augmentation (36.85%).

SVHN and MNIST

SVHN is digit recognition on house numbers. NIN's error rate is 2.35%, lower than maxout's 2.47%. In the same table, though, Multi-digit Number Recognition gets 2.16% and DropConnect 1.94%, both better than NIN.

On MNIST, NIN gets 0.47% and maxout 0.45%. The authors' explanation is that MNIST has already been tuned to a very low error rate.

Does Global Average Pooling Really Regularize?

To look at GAP on its own, the authors swap it back for fully connected layers, leave everything else unchanged, and compare on CIFAR-10:

Table: Excerpted from Table 5 of the paper.
Top layersTest error
mlpconv + fully connected11.59%
mlpconv + fully connected + Dropout10.88%
mlpconv + global average pooling10.41%

Fully connected without dropout is the worst, adding dropout helps somewhat, and GAP is the best.

Would an ordinary convolutional network get the same effect from GAP? The authors try the network from Hinton et al.'s dropout paper (three convolutional layers plus one locally connected layer). With fully connected layers and no dropout it gets 17.56%, with dropout 15.99%, and with GAP 16.46%, about one percentage point better than no dropout but worse than dropout. The authors' explanation goes back to the precondition from earlier, that asking linear convolutions plus ReLU to learn each class's confidence map directly may be asking too much.

Did the Last Layer Really Become Confidence Maps?

Two 10-by-10 grids. Each row is one CIFAR-10 test image, with the original on the left followed by the last layer's feature maps for the 10 classes; the ones outlined in red along the diagonal are the feature maps for each image's true class, mostly the brightest, with the bright spots roughly where the object is in the original image
Figure 4 from the paper, excerpted from page 9 of the v3 PDF. Feature maps from the last mlpconv layer, showing only the top 10% of activations; the classes, in order, are airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck, and the red boxes mark each image's true class. The left and right sets are simply different examples.

Each row is one test image and its response on the 10 feature maps. The red box marks the true-class map, which is usually the brightest in its row. GAP forces that by design anyway. Look next at the true-class feature map, whose brightest spots fall roughly where the object sits in the original image. The authors single out objects with clear structure, such as the car.

These feature maps were trained with class labels only and never saw a single bounding box. In their conclusion, the authors note that this makes object detection with NIN possible.

Conclusion

NiN's two components were designed together. The mlpconv layers give each local patch a stronger model, and that is what allows GAP to demand that the last layer's feature maps correspond directly to classes. Experimentally, the CIFAR-10 and CIFAR-100 results and the GAP comparison both support this design; on an ordinary convolutional network, GAP used on its own loses some of its effect.

NiN made its mark on ImageNet as well. According to the ILSVRC overview paper, NUS, winner of the 2014 detection challenge (in the track using only the provided data), used network-in-network within the R-CNN framework.

Both of NiN's components were later taken apart and used separately. 1×11\times1 convolutions adjust the channel count in the bottleneck structures of GoogLeNet and ResNet, and global average pooling handles the ending, though it's usually followed by one more fully connected layer and no longer requires each feature map to correspond to one class. The next time you open the code of a classification network, that AdaptiveAvgPool2d(1) line near the end traces back to this paper.

As for “the last layer's feature maps show where the object is,” that idea wasn't put to serious use until CAM, a full two years later.