Back to paper library
Paper notesarXiv 2016AAAI 2017

Inception-v4

Much Faster, a Little More Accurate

Original paper

Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning

Paper authors

Christian Szegedy · Sergey Ioffe · Vincent Vanhoucke · Alex Alemi

Publication
AAAI 2017Conference
First submitted to arXiv
arXiv:1602.07261
Cite this paper · BibTeX

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

@misc{classiccnnsinceptionv42016,
  title = {{Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning}},
  author = {Christian Szegedy and Sergey Ioffe and Vincent Vanhoucke and Alex Alemi},
  year = {2016},
  eprint = {1602.07261},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1602.07261}
}
On this page

The ILSVRC 2015 classification winner was Microsoft Research's ResNet. Its architecture is quite traditional, convolutions stacked layer upon layer, with residual connections as the only addition; as a single model, it scores about the same as the Inception-v3 that Google had just published.

Inception keeps computation down with multi-branch modules and carefully budgeted channel counts, while ResNet uses residual connections to make very deep networks trainable.

So what happens if you combine them?

In February 2016, Christian Szegedy, Sergey Ioffe, Vincent Vanhoucke, and Alex Alemi of Google released this paper. The title packs in the new Inception-v4, Inception-ResNet with residual connections added, and what effect residual connections actually have on training.

Defining the Problem

This paper tackles two problems at once.

The first is residual connections. The ResNet authors argue that residual connections are inherently necessary for training very deep convolutional networks. Inception networks are very deep to begin with, so replacing the “concatenate the channels” step at the end of an Inception module with “add back the input” seems natural. But where does the benefit lie? In final accuracy, or somewhere else?

The second is Inception itself. The authors admit that Inception-v3 carries a lot of historical baggage. Earlier models were trained with DistBelief, where each replica had to be split into several sub-networks to fit in memory, and the number of filters in each layer was carefully tuned to balance computation across the sub-networks. After the move to TensorFlow, that constraint was gone. On top of that, they had always been conservative about changing the architecture, modifying one component at a time while keeping the rest fixed, and the network grew more and more complicated as a result.

Now that the baggage can be set down, can Inception become simpler, deeper, and wider?

Solving the Problem

Dropping the Baggage: Inception-v4

The overall Inception-v4 architecture, from bottom to top: Input 299x299x3, Stem (output 35x35x384), 4 x Inception-A (35x35x384), Reduction-A (17x17x1024), 7 x Inception-B (17x17x1024), Reduction-B (8x8x1536), 3 x Inception-C (8x8x1536), Average Pooling (1536), Dropout (keep 0.8), Softmax (1000)
Figure 9 from the paper, excerpted from page 5 of the v2 PDF. The overall Inception-v4 architecture, with the output size of each stage on the right.

This looks a lot like Inception-v3's architecture table, with the same three resolutions (35×3535\times35, 17×1717\times17, 8×88\times8), several Inception modules stacked at each, and reduction modules in between to move to the next resolution. The difference is that Inception-v4 uses just one kind of module per resolution, and more of them, with 4 Inception-A, 7 Inception-B, and 3 Inception-C in order.

The three modules carry on Inception-v3's factorization methods:

  • Inception-A (35×3535\times35): four branches, the longest of which replaces 5×55\times5 with two 3×33\times3 layers; each branch outputs 96 channels, for 384 in total.
  • Inception-B (17×1717\times17): uses asymmetric 1×71\times7 and 7×17\times1 convolutions, for 1024 channels in total.
  • Inception-C (8×88\times8): outputs 1×31\times3 and 3×13\times1 side by side, for 1536 channels in total.

Convolutions marked “V” in the figures use valid padding: no zero padding, so the output shrinks. Unmarked ones use same padding, so the output is the same size as the input.

The Entrance

Compared with Inception-v3, the most visible change is at the start of the network. The authors call it the stem:

The Inception-v4 stem, from bottom to top: Input 299x299x3; 3x3 Conv (32 stride 2 V) gives 149x149x32; 3x3 Conv (32 V) gives 147x147x32; 3x3 Conv (64) gives 147x147x64; it then splits into two paths, 3x3 MaxPool (stride 2 V) and 3x3 Conv (96 stride 2 V), and Filter concat gives 73x73x160; it splits again into two paths, 1x1 Conv (64) followed by 3x3 Conv (96 V), and 1x1 Conv (64), 7x1 Conv (64), 1x7 Conv (64), 3x3 Conv (96 V), and Filter concat gives 71x71x192; finally it splits into 3x3 Conv (192 V) and MaxPool (stride=2 V), and Filter concat gives 35x35x384
Figure 3 from the paper, excerpted from page 3 of the v2 PDF. The stem shared by Inception-v4 and Inception-ResNet-v2.

The first three layers are the same as in Inception-v3, going from 299×299299\times299 to 147×147×64147\times147\times64. Then come three rounds of “split, then join,” each with one branch that does the downsampling or with two branches processed separately and then merged, giving the shapes marked in the figure: 73×73×16073\times73\times160, 71×71×19271\times71\times192 and 35×35×38435\times35\times384. Pooling doesn't change the channel count, so the first merge is 64+96=16064+96=160 and the last is 192+192=384192+192=384.

The first and third merges use Inception-v3's method for shrinking feature maps, placing a stride-2 convolution and a stride-2 pooling side by side to avoid the information bottleneck that pooling first would create. This time even the start of the network does it.

Wiring Residuals into Inception

For the residual versions of Inception, the authors use cheaper modules. Take Inception-ResNet-v2's 35×3535\times35 module as an example:

The Inception-ResNet-A module: the Relu activation at the bottom splits into four paths. The leftmost goes straight to the plus sign at the top; the other three branches are 1x1 Conv (32); 1x1 Conv (32) followed by 3x3 Conv (32); and 1x1 Conv (32) followed by 3x3 Conv (48) and then 3x3 Conv (64). The outputs of the three branches go together into a 1x1 Conv (384 Linear), are added to the pass-through path on the far left, and finally pass through a Relu activation
Figure 16 from the paper, excerpted from page 8 of the v2 PDF. The 35×3535\times35 module of Inception-ResNet-v2 (Inception-ResNet-A).

Compared with a pure Inception module, two things are different:

  1. The branches are narrower. The three branches end up with only 32+32+64=12832+32+64=128 channels, far fewer than the input's 384.
  2. After the branches are concatenated, there's an extra 1×11\times1 convolution with no activation function that expands the channels back to 384 so the result can be added to the input. The authors call it a filter-expansion layer; it makes up for the dimensionality reduction caused by the Inception module.
Python
import torch
import torch.nn as nn

def conv(cin, cout, k):
    return nn.Sequential(nn.Conv2d(cin, cout, k, padding=k // 2, bias=False), nn.BatchNorm2d(cout), nn.ReLU())

class InceptionResNetA(nn.Module):
    def __init__(self, channels=384, scale=0.1):
        super().__init__()
        self.b1 = conv(channels, 32, 1)
        self.b2 = nn.Sequential(conv(channels, 32, 1), conv(32, 32, 3))
        self.b3 = nn.Sequential(conv(channels, 32, 1), conv(32, 48, 3), conv(48, 64, 3))
        self.expand = nn.Conv2d(32 + 32 + 64, channels, 1)   # 1×1, no activation function
        self.scale = scale

    def forward(self, x):
        branches = torch.cat([self.b1(x), self.b2(x), self.b3(x)], dim=1)
        residual = self.expand(branches)
        print("Concatenated branches:", tuple(branches.shape[1:]), "→ expanded by 1×1:", tuple(residual.shape[1:]))
        return torch.relu(x + self.scale * residual)

x = torch.randn(2, 384, 35, 35)
print("Output:", tuple(InceptionResNetA()(x).shape[1:]))
Text
Concatenated branches: (128, 35, 35) → expanded by 1×1: (384, 35, 35)
Output: (384, 35, 35)

The scale in the code is the star of the next section; set it aside for now.

The authors tried several residual versions, but the paper details only two:

Table: Compiled from Section 3.2 and Figure 15 of the paper. The two networks share the same overall structure; their modules differ in channel counts.
NetworkComparable costStemBody
Inception-ResNet-v1About the same as Inception-v3Its own stem (Figure 14)5 × A, Reduction-A, 10 × B, Reduction-B, 5 × C
Inception-ResNet-v2About the same as Inception-v4Same as Inception-v4 (Figure 3)As above, with wider modules

Although Inception-ResNet-v2 and Inception-v4 have comparable raw computational cost, the authors note that in practice Inception-v4 is much slower per training step, probably because it has more layers.

Also, Inception-ResNet applies batch normalization only on top of the ordinary layers, not after the additions. The authors say that using batch normalization throughout should be better, but on layers with large activations it takes up a disproportionate amount of GPU memory. To keep each model replica on a single GPU, they dropped those BN layers, which let them stack many more modules.

Scaling Down the Residuals to Steady Training

Next, the authors found that when the number of filters exceeded 1000, the residual versions became unstable, and the network would “die” early in training. Concretely, after a few tens of thousands of iterations, the last layer before average pooling output nothing but zeros. Neither lowering the learning rate nor adding an extra batch normalization to that layer could bring it back.

What eventually worked was multiplying the residual by a small constant before adding it.

Diagram of residual scaling: the Relu activation at the bottom splits into two paths; one goes straight to the plus sign at the top, while the other passes through an Inception block and then an Activation Scaling block before reaching the plus sign; the addition is followed by a Relu activation
Figure 20 from the paper, excerpted from page 9 of the v2 PDF. Scaling the residual inside an Inception-ResNet module; the constant is usually around 0.1.

The authors generally pick values between 0.1 and 0.3. When the ResNet paper ran into instability with very deep networks, it used two-phase training: first a “warm-up” at a very low learning rate, then a higher learning rate. The authors found that with very many filters, even a learning rate of 0.00001 couldn't hold off the instability, and the high learning rate that followed could undo whatever the warm-up achieved. Scaling the residuals was far more reliable by comparison. Even where the network could train without scaling, adding it never hurt final accuracy, and it made training more stable.

The paper doesn't analyze why the network “dies.” Still, the Inception-ResNet branches contain batch normalization, so their output size stays roughly fixed, while the main path has no batch normalization after the addition, so the signal accumulates with every module. Without scaling, every module adds a signal about as large as the main path's, and after 40 modules the main path's standard deviation grows to about 41≈6.4\sqrt{41}\approx6.4 times; with a scale of 0.1, each module makes only a small correction, and the main-path signal comes mostly from the identity path. This is only a simplified estimate at initialization and cannot explain the “dying” midway through training; what the paper establishes is only the experimental result that wide residual networks train stably once scaled.

Training Setup

The setup is almost the same as Inception-v3's, using TensorFlow distributed training, this time with 20 replicas, each running on one NVIDIA Kepler GPU. The best models use RMSProp (decay 0.9, ϵ=1.0\epsilon=1.0) with a learning rate of 0.045, multiplied by 0.94 every two epochs; evaluation uses a running average of the parameters.

Discussion

Residuals Make Training Much Faster

A line chart with epochs on the horizontal axis (20 to 200) and top-1 error on the vertical axis (15% to 29%). The green dashed line is inception-v3, and the red solid line is inception-resnet-v1. The red line falls much faster, nearing 22% by around 80 epochs, while the green line doesn't catch up until around 160 epochs; both lines end up just above 21%
Figure 21 from the paper, excerpted from page 9 of the v2 PDF. Top-1 error (single crop) during training for Inception-v3 and Inception-ResNet-v1, which have similar computational cost.

The red line is Inception-ResNet-v1, with residuals; the green line is Inception-v3. The red line falls much faster, yet both lines end up in about the same place, with the residual version slightly worse on top-1 and slightly better on top-5. For the Inception-v4 and Inception-ResNet-v2 pair, too, the residual version trains faster and finishes slightly better.

Comparing all four models, the authors judge that the residual versions converge faster, but that final accuracy depends mainly on model size.

Single-Model Results

Table: Excerpted from Table 2 of the paper. Single model, single crop, on the validation set excluding blacklisted images.
NetworkTop-1 errorTop-5 error
BN-Inception25.2%7.8%
Inception-v321.2%5.6%
Inception-ResNet-v121.3%5.5%
Inception-v420.0%5.0%
Inception-ResNet-v219.9%4.9%

Paired by similar computational cost, Inception-v3 and Inception-ResNet-v1 are nearly tied, and Inception-v4 and Inception-ResNet-v2 are only 0.1 percentage points apart. The gap between the two pairs is much larger than the gap within each pair between the versions with and without residuals.

Multi-crop results follow the same trend:

Table: Excerpted from Tables 3 and 4 of the paper, on the full 50,000-image validation set.
NetworkCropsTop-1 errorTop-5 error
ResNet-1521021.4%5.7%
Inception-v31219.8%4.6%
Inception-ResNet-v11219.8%4.6%
Inception-v41218.7%4.2%
Inception-ResNet-v21218.7%4.1%
ResNet-152dense19.4%4.5%
Inception-v314418.9%4.3%
Inception-ResNet-v114418.8%4.3%
Inception-v414417.7%3.8%
Inception-ResNet-v214417.8%3.7%

Ensembles

Table: Excerpted from Table 5 of the paper, on the full 50,000-image validation set. ResNet uses dense evaluation; the Inception models use 144 crops.
NetworkModelsTop-1 errorTop-5 error
ResNet-1526–3.6%
Inception-v3417.3%3.6%
Inception-v4 + 3 × Inception-ResNet-v2416.5%3.1%

One Inception-v4 plus three Inception-ResNet-v2 gives 3.1% top-5 error on the validation set. This ensemble was also submitted to the test server, scoring 3.08%. The authors make a point of saying that in the past year they had submitted results to the test server only twice, once for the BN-Inception paper and once for the ILSVRC 2015 CLSLOC competition, so the test-set number can be taken as a true estimate of generalization.

The authors also notice that single-model improvements become less pronounced once models are ensembled.

Are Residual Connections “Necessary”?

Back to the first question from the beginning. At least for image recognition, the authors say, their results don't support the ResNet paper's claim that residual connections are inherently necessary. Inception-v4 has no residual connections, yet it trains just fine and performs on par with Inception-ResNet-v2.

They also leave some room, noting that seeing the full extent of what residual connections offer may take deeper architectures and more measurement points. What is certain is that residual connections make training much faster, and that alone is reason enough to use them.

Conclusion

This paper delivers the pure-Inception Inception-v4 along with Inception-ResNet-v1 and v2, whose computational costs match Inception-v3 and Inception-v4, respectively, for three networks in all.

The authors picked the Inception-ResNet modules “in a somewhat ad hoc manner” (their own words), requiring only a computational cost close to the corresponding pure Inception model; they also tried bigger and wider versions, which performed very similarly on ImageNet. With the comparison set up this way, what residual connections mainly bring is training speed. What really opens up a gap is a bigger model, with Inception-v4 and Inception-ResNet-v2 both clearly better than the v3-class models.

If you're picking a model to use and training time matters, add residual connections; if final accuracy matters, model size counts for more than whether there are residuals. When the network is very wide, remember to multiply the residual by 0.1 to 0.3 before adding it back, or training may “die” partway through.

As for whether residuals are a necessity for training deep networks, ResNet and this paper each have their own view. Around the same time, the ResNet authors themselves were studying the right way to wire residuals, which is the subject of the next note, ResNet v2.