AI Logic

Architectures

GoogLeNet (Inception)

Updated:

Structure of GoogLeNet. Left: the overall flow (initial convolutions and pooling, 9 Inception modules, average pooling, fully connected layer) and the auxiliary classifiers for training that branch off from (4a) and (4d). Right: the inside of Inception module (3a) (4 branches, 1×1, 1×1 → 3×3, 1×1 → 5×5, and 3×3 max pooling → 1×1, concatenated along the channel axis)

Background and overview

GoogLeNet is a 22-layer convolutional neural network built by stacking "Inception modules," which place convolutions of different sizes (1×1, 3×3, 5×5) and pooling side by side and combine their outputs. It was published by Szegedy et al. at Google in 2014 and took first place in ILSVRC-2014 image classification. The design idea is called Inception, and GoogLeNet is one specific model based on it (later also called Inception v1).

The simplest way to improve a network's accuracy is to make it deeper and each layer wider (more channels). However, simply making it bigger causes the following two problems.

  • It becomes prone to overfitting: the number of parameters grows, and there is not enough labeled data.
  • Computation increases sharply: doubling the number of channels of two consecutive convolutional layers quadruples the computation.

GoogLeNet increased depth and width while keeping computation almost constant by reducing the number of channels with 1×1 convolutions before applying large convolutions. It was designed to keep inference at around 1.5 billion multiply-adds, with the goal of being usable on real devices.

The main results of the paper are as follows.

  • In ILSVRC-2014 image classification, it took first place with a top-5 error rate of 6.67% (second place was VGG with 7.32%).
  • It has one twelfth of the parameters of AlexNet, the winning model two years earlier.
  • In the object detection track of the same year, it also took first place with a mean average precision (mAP) of 43.9%.

The name GoogLeNet pays homage to LeNet-5, a pioneer of CNNs. The name Inception comes from the Network In Network paper and from the internet meme "we need to go deeper," which refers to the film.

Architecture

GoogLeNet uses ordinary convolutions for its first few layers and stacks 9 Inception modules on top of them. The left side of the figure at the top of the article shows the overall flow, and the right side shows the inside of one Inception module.

Inception module

A module feeds the previous layer's output into 4 branches simultaneously and concatenates their outputs along the channel axis.

  1. A 1×1 convolution
  2. A 1×1 convolution to reduce channels, followed by a 3×3 convolution
  3. A 1×1 convolution to reduce channels, followed by a 5×5 convolution
  4. A 3×3 max pooling (stride 1) followed by a 1×1 convolution to reduce channels

ReLU is applied after every convolution (including the channel-reducing 1×1 ones). None of the 4 branches changes the height or width, so their outputs can be stacked directly. With x\boldsymbol{x} as the output of the previous layer, the module's output can be written as follows.

Inception(x)=concat⁡(f1×1(x), f3×3(x), f5×5(x), fpool(x))\text{Inception}(\boldsymbol{x}) = \operatorname{concat}\big(f_{1\times1}(\boldsymbol{x}),\ f_{3\times3}(\boldsymbol{x}),\ f_{5\times5}(\boldsymbol{x}),\ f_{\text{pool}}(\boldsymbol{x})\big)

concat is concatenation along the channel axis, and each ff is the computation of a branch. For example, the first module (3a) produces 64, 128, 32, and 32 channels from a 192-channel input, outputting 256 channels in total.

Why 1×1 convolutions are used to reduce channels

The paper first considered a naive form that simply places the 4 branches side by side. In that form, however, applying 5×5 convolutions to an input with many channels is too expensive. Moreover, the pooling branch outputs as many channels as its input, so the number of output channels grows with every module stacked, and within a few stages the computation becomes unmanageable.

So a 1×1 convolution is placed before the 3×3 and 5×5 convolutions (after it in the pooling branch) to reduce the number of channels. Comparing the number of multiplications per output position in the 5×5 branch of (3a) gives the following (height and width stay at 28×28).

Form of the 5×5 branchMultiplications per positionWhole 28×28 map
5×5 applied directly to 192 channels (32 channels)52×192×32=153,6005^2 \times 192 \times 32 = 153{,}600About 120M
Reduce to 16 channels with 1×1, then 5×5192×16+52×16×32=15,872192 \times 16 + 5^2 \times 16 \times 32 = 15{,}872About 12.4M

Reducing the channels cuts the computation to roughly one tenth. Since there is also a ReLU after the 1×1 convolution, it has the added effect of increasing the number of nonlinear layers.

Overall flow

An image (224×224×3, with the RGB mean subtracted) flows in the following order (Table 1 of the paper).

LayerOutput shapeParametersComputation (multiply-adds)
7×7 convolution (stride 2)112×112×642.7K34M
3×3 max pooling (stride 2)56×56×640—
1×1 → 3×3 convolution56×56×192112K360M
3×3 max pooling (stride 2)28×28×1920—
Inception (3a), (3b)28×28×480159K, 380K128M, 304M
3×3 max pooling (stride 2)14×14×4800—
Inception (4a)–(4e)14×14×832364K–840K73M–170M
3×3 max pooling (stride 2)7×7×8320—
Inception (5a), (5b)7×7×10241072K, 1388K54M, 71M
7×7 average pooling1×1×10240—
Dropout (40%)1×1×10240—
Fully connected (softmax)10001000K1M

Counting only layers with parameters gives 22 layers (27 if pooling is also counted). Summing the parameters in Table 1 gives about 6.8 million, and the computation is about 1.5 billion operations. In the paper's overall diagram (Figure 3), the same local response normalization (LRN) as in AlexNet appears after the first max pooling and after the 3×3 convolution.

Inception modules are used only in the higher layers to save memory during training, and the paper states that this is not strictly necessary. Also, instead of stacking fully connected layers at the end, it uses global average pooling (following Network In Network), with only a single fully connected layer for classification. This improved top-1 accuracy by about 0.6 points.

Auxiliary classifiers

Because the network is deep, there was a concern about whether gradients would reach the lower layers. So small classifiers (auxiliary classifiers) are attached to the outputs of the intermediate modules (4a) and (4d).

  1. 5×5 average pooling with stride 3 (output 4×4×512, or 4×4×528 for (4d))
  2. A 1×1 convolution with 128 channels and ReLU
  3. A fully connected layer with 1024 neurons and ReLU
  4. Dropout that sets 70% of the outputs to 0
  5. A 1000-class fully connected layer and softmax function

During training, the losses of the auxiliary classifiers are multiplied by 0.3 and added to the total loss. At inference, the auxiliary classifiers are removed.

L=Lmain+0.3 (Laux1+Laux2)L = L_{\text{main}} + 0.3\,\big(L_{\text{aux1}} + L_{\text{aux2}}\big)

Training

GoogLeNet was trained using only CPUs on DistBelief, Google's distributed training system. The paper estimates that it could be trained to convergence in about a week on a few high-end GPUs.

ItemValue
LossCross-entropy (main + auxiliary classifiers × 0.3)
OptimizerAsynchronous SGD, momentum 0.9
Learning rateDecreased by 4% every 8 epochs
Weights used for inferenceAverage of the weights during training (Polyak averaging)
Dropout40% before the main fully connected layer, 70% in the auxiliary classifiers

The way images were cropped changed many times over the months leading up to the competition, and the paper cautions that it cannot point to a single method as definitively the best. With that caveat, it lists the following data augmentation, whose effectiveness was confirmed after the competition.

  • Randomly crop regions covering 8% to 100% of the image area, with aspect ratios between 3/4 and 4/3
  • Alter brightness and color (Howard's method)
  • Randomly choose the interpolation method used for resizing (bilinear, area, nearest neighbor, cubic) (the effect is unclear)

The first cropping method is based on the same idea as the method later widely used as RandomResizedCrop in PyTorch and other libraries.

Testing (the competition submission)

  1. Train 7 GoogLeNets with the same architecture (one of them wider), varying only the cropping and the order in which the training data is seen.
  2. Resize each image so that its shorter side is 256, 288, 320, or 352, and take the left, center, and right squares of each. From each square, take the four corner and center 224×224 crops and the whole square resized to 224×224, plus their horizontal flips, producing 4×3×6×2=1444 \times 3 \times 6 \times 2 = 144 crops per image.
  3. Average the softmax outputs over all crops and all models.

Why accuracy improves so efficiently

The starting point of GoogLeNet's idea is the problem that sparsely connected networks would ideally be better, but today's computers are much faster at dense computation.

  • Approximating a sparse structure with a combination of dense components: according to theoretical work (Arora et al.), if a large, sparse network represents the data well, an optimal structure can be built layer by layer by clustering neurons whose outputs are highly correlated. This also resonates with the Hebbian principle that "neurons that fire together, wire together." The Inception module is an attempt to approximate this sparse structure with a combination of dense 1×1, 3×3, and 5×5 convolutions.
  • Looking at regions of various sizes at once: in layers close to the input, highly correlated neurons concentrate in small regions and can be captured with 1×1 convolutions. Features spread over wider regions are captured with 3×3 and 5×5 convolutions. By placing convolutions of different sizes side by side, the next layer can use features extracted at multiple scales together. Since features covering wider regions are expected to increase in higher layers, the paper increases the share of 3×3 and 5×5 convolutions in higher layers.
  • Compressing only where needed: 1×1 convolutions reduce dimensions only right before the large convolutions. This makes it possible to increase the width and number of stages of the modules while keeping computation down. According to the paper, this can be 2 to 3 times faster than a network of similar accuracy without Inception.

As an everyday analogy, an Inception module is like "using a magnifying glass, a loupe, and binoculars at the same time and reporting everything seen together." The 1×1 convolution plays the role of a preliminary survey that narrows down what to look at before using the heavy binoculars (5×5).

The paper itself cautiously states that it is not yet clear whether this success is really due to the design principle above (approximating a sparse structure). It says that verifying this would require checking whether automated systems that build structures by the same principle find similar, better structures.

Experimental results

History of ILSVRC image classification results (top-5 error rate on the test data, Table 2 of the paper)

TeamYearPlacetop-5 error rateExternal data
SuperVision (AlexNet)20121st16.4%None
SuperVision (AlexNet)20121st15.3%ImageNet 22k
Clarifai20131st11.7%None
Clarifai20131st11.2%ImageNet 22k
MSRA20143rd7.35%None
VGG20142nd7.32%None
GoogLeNet20141st6.67%None

GoogLeNet's 6.67% is a relative reduction of 56.5% compared with the 2012 AlexNet that used external data, and about 40% compared with Clarifai in 2013. It was also 6.67% on the validation data.

Effect of the number of models and crops (top-5 error rate on the validation data, Table 3 of the paper)

ModelsCropsEvaluationstop-5 error rateDifference from 1 model, 1 crop
11110.07%—
110109.15%−0.92
11441447.89%−2.18
7178.09%−1.98
710707.62%−2.45
714410086.67%−3.45

A single model with a single crop gives 10.07%, and the submitted 6.67% comes from averaging 7 models and 144 crops (1008 evaluations in total). The paper also notes that such a large number of crops may not be necessary in real applications.

Object detection (ILSVRC-2014 detection, 200 classes, mAP)

GoogLeNet used the same procedure as R-CNN, with an Inception model for the region classification part. An ensemble of 6 models achieved an mAP of 43.9% and took first place (the 2013 winner had 22.6%). A single model achieved 38.02%.

Caveats when using it

When using GoogLeNet, keep the following points in mind.

  • The GoogLeNet in libraries differs slightly from the paper: the GoogLeNet in PyTorch's torchvision inserts batch normalization after every convolution and does not use local response normalization. The source code also notes, as a known bug, that the 5×5 branch is actually a 3×3 convolution. The accuracy of the pre-trained weights is 69.8% top-1 and 89.5% top-5, with about 6.6 million parameters (official documentation).
  • Handling of the auxiliary classifiers: when pre-trained weights are loaded in torchvision, the auxiliary classifiers are removed by default. Specifying aux_logits=True keeps them, but their weights are not trained, so they must be trained by the user. Also, in model.train() the output is the tuple (logits, aux_logits2, aux_logits1), while in model.eval() only the main output is returned.
  • Input normalization: when pre-trained weights are used in torchvision, transform_input=True is set, and inside the model, images normalized with the ImageNet mean and standard deviation are converted back to a normalization that maps pixels to −1 to 1 (to match the assumptions of the original ported weights). Use the preprocessing attached to the weights, weights.transforms().
  • The effect of the auxiliary classifiers is considered limited: auxiliary classifiers were intended to deliver gradients to the lower layers and to act as regularization. Later, batch normalization and the shortcut connections of ResNet became widespread, and they are rarely used in today's deep networks.

The paper's 6.67% is the average over 7 models and 144 crops per image. With 1 model and 1 crop, it is 10.07%. When comparing with other models, match the number of models and the number of crops.

Comparison with other models

GoogLeNet and VGG, from the same year, both showed that "deeper is better," but they go deeper in contrasting ways. Compared from the same viewpoints, they look like this (error rates are top-5 on the ILSVRC test data from each paper).

ModelWeighted layersHow layers are builtParametersComputationtop-5 error rate
AlexNet8Convolutions with large kernels and fully connected layersAbout 60M—15.3%
VGG-1616Repeats 3×3 convolutions in the same formAbout 138MAbout 15.3B6.8% (2 models)
GoogLeNet22Places convolutions of different sizes side by side and reduces dimensions with 1×1About 6.8MAbout 1.5B6.67% (7 models)
ResNetUp to 152Bottleneck blocks + shortcut connections—About 11.3B for ResNet-1523.57% (6 models of different depths)

Computation is the number of multiply-adds; the values for VGG and ResNet are from the ResNet paper (VGG-16 is 15.3×10915.3 \times 10^9 and ResNet-152 is 11.3×10911.3 \times 10^9), and the value for GoogLeNet is the sum from Table 1 of the paper.

GoogLeNet achieved accuracy comparable to VGG with about one twentieth of the parameters and about one tenth of the computation. On the other hand, its structure is complex, the number of channels must be chosen by hand for each module, and it is not as easy to modify as VGG. The "bottleneck" idea of reducing channels with 1×1 convolutions was carried over into ResNet's bottleneck blocks.

Rough guidelines for choosing are as follows.

  • To learn how to design CNNs with low computation: GoogLeNet's channel reduction with 1×1 convolutions is a fundamental technique in designing lightweight models.
  • As a backbone for image classification or detection: today it is common to choose ResNet, which has batch normalization and shortcut connections, or even lighter models such as MobileNet and EfficientNet.
  • When a simple structure is preferred: for uses such as extracting features from intermediate layers, VGG can be easier to work with.

PyTorch example

Show code
python
import torch
import torch.nn as nn
import torch.nn.functional as F
from PIL import Image
from torchvision.models import googlenet, GoogLeNet_Weights

"""
1. Load torchvision's pre-trained GoogLeNet and classify an image
2. One training step of GoogLeNet with auxiliary classifiers, using the same loss as the paper (main + 0.3 × auxiliary)
(torchvision's GoogLeNet has batch normalization after each convolution and no local response normalization)
"""

# --- 1. Inference with pre-trained weights ---
weights = GoogLeNet_Weights.IMAGENET1K_V1     # Same as GoogLeNet_Weights.DEFAULT
model = googlenet(weights=weights)            # Auxiliary classifiers are removed (aux_logits=False)
model.eval()                                  # Disable dropout; BN uses the mean and variance accumulated during training

preprocess = weights.transforms()             # Resize to 256, center-crop 224×224, normalize by mean and std
image = Image.open("cat.jpg").convert("RGB")
x = preprocess(image).unsqueeze(0)            # [1, 3, 224, 224]
with torch.no_grad():
  probs = model(x).softmax(dim=1)             # In eval mode, only the main output: [1, 1000]
top5 = probs.topk(5, dim=1)
for p, i in zip(top5.values[0], top5.indices[0]):
  print(f"{weights.meta['categories'][i]}: {p.item():.3f}")

# Inside Inception module (3a): the outputs of the 4 branches (branch1-4) are concatenated along the channel axis
print(model.inception3a)

# --- 2. Training from scratch with auxiliary classifiers (10-class example) ---
net = googlenet(weights=None, aux_logits=True, num_classes=10, init_weights=True)
optimizer = torch.optim.SGD(net.parameters(), lr=0.01, momentum=0.9)
images = torch.randn(8, 3, 224, 224)
labels = torch.randint(0, 10, (8,))

net.train()
out = net(images)                             # In train mode, a tuple of (logits, aux_logits2, aux_logits1)
loss = F.cross_entropy(out.logits, labels) + 0.3 * (
  F.cross_entropy(out.aux_logits1, labels) + F.cross_entropy(out.aux_logits2, labels))
optimizer.zero_grad()
loss.backward()
optimizer.step()

net.eval()                                    # Auxiliary classifiers are not used at inference
with torch.no_grad():
  logits = net(images)                        # [8, 10]

FAQ

Q. Are GoogLeNet and Inception the same thing?
A.

Inception is the name of the design idea (a family of networks) of stacking modules that place convolutions of different sizes side by side, while GoogLeNet is the name of one specific model of it submitted to ILSVRC-2014. GoogLeNet was later also called Inception v1, and improved versions that adopted batch normalization and other techniques (such as Inception-v3) followed.

Q. What does a 1×1 convolution do?
A.

At each spatial position, it mixes the channel values into a different number of channels. In GoogLeNet, it is used before the 3×3 and 5×5 convolutions to reduce the number of channels and keep computation down. For example, the 5×5 branch of (3a) reduces 192 channels to 16 before applying the 5×5 convolution, cutting the computation to roughly one tenth. Since a ReLU follows, it also adds nonlinear layers.

Q. Are the auxiliary classifiers used at inference?
A.

No. The auxiliary classifiers are attached only during training to deliver gradients from the intermediate layers (4a) and (4d), and their losses are multiplied by 0.3 and added to the total loss. At inference they are removed, and only the main output is used. In torchvision as well, only the main output is returned in model.eval().

References

  1. Szegedy, C., Liu, W., Jia, Y., Sermanet, P., Reed, S., Anguelov, D., Erhan, D., Vanhoucke, V., & Rabinovich, A. (2015). Going Deeper with Convolutions. CVPR 2015. arXiv:1409.4842.
  2. Lin, M., Chen, Q., & Yan, S. (2014). Network In Network. ICLR 2014. arXiv:1312.4400.
  3. Simonyan, K., & Zisserman, A. (2015). Very Deep Convolutional Networks for Large-Scale Image Recognition. ICLR 2015. arXiv:1409.1556.
  4. PyTorch. torchvision.models.googlenet (GoogLeNet_Weights).
  5. PyTorch. torchvision/models/googlenet.py (source code).