AI Logic

Architectures

MobileNet

Updated:

Structure of MobileNet. The left side shows the overall flow (a 3×3 convolution, 13 depthwise separable convolution blocks, global average pooling, and a fully connected layer); the right side shows the inside of a block (a standard convolution layer compared with a layer split into a 3×3 depthwise convolution and a 1×1 convolution) and the cost formula with the width multiplier and resolution multiplier

Background and Overview

MobileNet is a lightweight convolutional neural network for smartphones and embedded devices, built by replacing standard convolutions with depthwise separable convolutions. It was proposed by Howard et al. at Google in 2017. Its defining feature is that the size and speed of the model can be tuned with just two values: the width multiplier α\alpha and the resolution multiplier ρ\rho.

Until then, image recognition models such as VGG and ResNet had improved accuracy by growing deeper and larger. In settings such as robotics, autonomous driving, and augmented reality, however, recognition must run on the spot on devices with limited compute, so small size and speed matter as much as accuracy. MobileNet trades a small loss in accuracy for a large reduction in computation and parameters.

The main results of the paper are as follows.

  • Its ImageNet accuracy is 70.6%, nearly the same as VGG-16 (71.5%), yet it uses about 1/32 of the parameters (4.2M vs. 138M) and about 1/27 of the multiply-adds (computation).
  • It is more accurate than GoogLeNet (69.8%) with less than 1/2.5 of the computation.
  • "0.50 MobileNet-160", shrunk with the two multipliers, is about 3 points more accurate than AlexNet with about 1/45 of the parameters.
  • On tasks beyond classification, such as object detection, fine-grained classification, face attributes, and geolocation, it came close to the accuracy of large models with little computation.

MobileNet became the basis for the later MobileNetV2 and MobileNetV3. To distinguish it from them, this first version is also called "MobileNetV1".

Theory: Depthwise Separable Convolution and Two Multipliers

The idea behind MobileNet is to split what a standard convolution does in one step, "spatial filtering" and "combining channels", into two layers. The mechanism and the derivation of the formulas are covered in the depthwise separable convolution article, so this section focuses on how MobileNet uses it.

Let the input be DF×DFD_F \times D_F with MM channels, the output have NN channels, and the filter size be DK×DKD_K \times D_K. The cost (number of multiply-adds) of a standard convolution is as follows (Eq. 2 in the paper).

DK⋅DK⋅M⋅N⋅DF⋅DFD_K \cdot D_K \cdot M \cdot N \cdot D_F \cdot D_F

One MobileNet block computes the following steps.

  1. Depthwise convolution: Apply one 3×33 \times 3 filter to each input channel. Channels are not mixed. In blocks that halve the height and width, this layer uses stride 2.
  2. Apply batch normalization (BN) and ReLU.
  3. Pointwise convolution: A 1×11 \times 1 convolution combines the MM channels at each pixel into NN channels.
  4. Apply BN and ReLU again.

The cost of this block is the sum of the two layers (Eq. 5). Its ratio to a standard convolution is 1N+1DK2\frac{1}{N} + \frac{1}{D_K^2}, so with 3×33 \times 3 filters the cost drops to about 1/8 to 1/9.

DK⋅DK⋅M⋅DF⋅DF+M⋅N⋅DF⋅DFD_K \cdot D_K \cdot M \cdot D_F \cdot D_F + M \cdot N \cdot D_F \cdot D_F

For cases that need an even smaller model, MobileNet provides two multipliers.

  • Width multiplier α\alpha (0<α≤10 < \alpha \le 1): Multiplies the number of channels in every layer by α\alpha. Because both inputs and outputs shrink by α\alpha, computation and parameters scale by roughly α2\alpha^2. The paper uses 1, 0.75, 0.5, and 0.25.
  • Resolution multiplier ρ\rho (0<ρ≤10 < \rho \le 1): Shrinks the input image so that the height and width of every layer scale by ρ\rho. Computation scales by ρ2\rho^2, but the number of parameters does not change. In practice, ρ\rho is set by choosing an input size of 224, 192, 160, or 128.

With both multipliers, the cost of one layer becomes the following (Eq. 7).

DK⋅DK⋅αM⋅ρDF⋅ρDF+αM⋅αN⋅ρDF⋅ρDFD_K \cdot D_K \cdot \alpha M \cdot \rho D_F \cdot \rho D_F + \alpha M \cdot \alpha N \cdot \rho D_F \cdot \rho D_F

Table 3 of the paper shows these effects stacked one after another on a single internal MobileNet layer (DK=3D_K = 3, M=N=512M = N = 512, DF=14D_F = 14).

Layer typeMult-adds (millions)Parameters (millions)
Standard convolution4622.36
Depthwise separable convolution52.30.27
Plus α=0.75\alpha = 0.7529.60.15
Plus ρ=0.714\rho = 0.71415.10.15

The width and resolution multipliers do not shrink a trained model. Once the multipliers are chosen, a model of that size is trained from scratch.

Overall Architecture

MobileNet is a simple, unbranched structure: only the first layer is a standard convolution, and the rest is a stack of depthwise separable convolution blocks. In the figure at the top of the article, the left side shows the overall flow and the right side shows the inside of a block.

An image flows through the network in the following order (for a 224×224 ImageNet image; Table 1 of the paper).

  1. A 3×33 \times 3 standard convolution (32 channels, stride 2) reduces it to 112×112.
  2. Thirteen depthwise separable convolution blocks are stacked.
    • The number of channels grows 64 → 128 → 256 → 512 → 1024.
    • Height and width are halved not by pooling but by setting the stride of the depthwise convolution to 2 (112 → 56 → 28 → 14 → 7).
    • The run of five blocks at 14×14 with 512 channels is the core of the network.
  3. A 7×7 average pooling (global average pooling) produces a 1024-dimensional vector.
  4. A 1000-class fully connected layer and a softmax function output the class probabilities.

Every layer except the fully connected layer is followed by batch normalization and ReLU. Counting depthwise and pointwise convolutions as separate layers, the network has 28 layers.

The shape of each stage is as follows ("Downsampling" means the block whose depthwise convolution uses stride 2).

Output sizeBlocksOutput channelsDownsampling
112×112164None
56×562128First block
28×282256First block
14×146512First block
7×721024First block

The ImageNet training settings in the paper are as follows.

ItemValue
OptimizationRMSprop (asynchronous gradient descent, as in Inception V3)
RegularizationWeaker than for large models; no auxiliary classifiers and no Label Smoothing
Data augmentationLimits the size of small crops and reduces image distortions
Weight DecayVery small or none on the depthwise convolution filters

Small models are less prone to overfitting, so regularization and data augmentation are weakened.

Why It Is Light and Fast

MobileNet is light and fast not only because it reduces computation but also because it concentrates nearly all of the remaining computation in 1×1 convolutions, which can be computed quickly.

Table 2 of the paper shows the share of computation and parameters by layer type.

Layer typeShare of mult-addsShare of parameters
1×1 convolution94.86%74.59%
3×3 depthwise convolution3.06%1.06%
3×3 standard convolution (first layer)1.19%0.02%
Fully connected layer0.18%24.33%

About 95% of the computation is in 1×1 convolutions. A 1×1 convolution simply multiplies the channel vector at each pixel by a matrix, so it can be computed directly as a matrix multiplication (GEMM). Turning a standard 3×33 \times 3 convolution into a matrix multiplication requires rearranging the input in memory (im2col), but a 1×1 convolution does not. Matrix multiplication is one of the most heavily optimized operations on any device.

The paper notes that low computation alone is not enough: it also matters that the computation takes a form that can be executed efficiently. For example, making the weights sparse to cut computation does not help unless the sparsity is very high, because sparse matrix operations are otherwise no faster than dense ones.

As an everyday analogy, it is like moving house: besides having fewer belongings, it helps to pack what remains into boxes of the same size so they can be moved together on a hand truck.

Depthwise convolutions account for only about 3% of the total computation. The paper therefore notes that further factorizing them spatially, for example splitting 3×33 \times 3 into 3×13 \times 1 and 1×31 \times 3, would save almost no computation.

Experimental Results

Comparison with standard convolutions (ImageNet accuracy, compared with the same structure using standard convolutions in the blocks; Table 4 of the paper)

ModelAccuracyMult-adds (millions)Parameters (millions)
MobileNet with standard convolutions71.7%4,86629.3
MobileNet70.6%5694.2

Accuracy drops by about 1 point, while computation falls to about 1/8.6 and parameters to about 1/7.

Narrower or shallower (Table 5 of the paper)

ModelAccuracyMult-adds (millions)Parameters (millions)
0.75 MobileNet (width ×0.75)68.4%3252.6
Shallow MobileNet (five 14×14 blocks removed)65.3%3072.9

At similar computation, making the network narrower gave a result 3 points better than removing layers.

Width multiplier and resolution multiplier (Tables 6 and 7 of the paper)

ModelAccuracyMult-adds (millions)Parameters (millions)
1.0 MobileNet-22470.6%5694.2
0.75 MobileNet-22468.4%3252.6
0.5 MobileNet-22463.7%1491.3
0.25 MobileNet-22450.6%410.5
1.0 MobileNet-19269.1%4184.2
1.0 MobileNet-16067.2%2904.2
1.0 MobileNet-12864.4%1864.2

"0.75 MobileNet-224" is the model with width multiplier 0.75 and a 224×224 input. Accuracy declines smoothly and drops sharply only when α\alpha is reduced to 0.25. Lowering the resolution does not change the number of parameters.

Comparison with other models (Tables 8 and 9 of the paper)

ModelAccuracyMult-adds (millions)Parameters (millions)
1.0 MobileNet-22470.6%5694.2
GoogLeNet69.8%1,5506.8
VGG-1671.5%15,300138
0.50 MobileNet-16060.2%761.32
SqueezeNet57.5%1,7001.25
AlexNet57.2%72060

Object detection (COCO, mAP@[.5:.95]; Table 13 of the paper)

DetectorBackbonemAPMult-adds (billions)Parameters (millions)
SSD 300Inception V222.0%3.813.7
SSD 300MobileNet19.3%1.26.8
Faster R-CNN 600VGG25.7%149.6138.5
Faster R-CNN 600MobileNet19.8%30.56.1

For detection, mAP is lower than with a large backbone, but computation and model size shrink by a factor of several to several dozen. For face attribute classification, combining MobileNet with knowledge distillation reached a mean AP of 88.7% with 568 million mult-adds, surpassing the original large classifier (86.9% mean AP, 1,600 million mult-adds) (Table 12 of the paper).

Practical Considerations

Keep the following points in mind when using MobileNet.

  • Apply little or no weight decay to depthwise convolutions: A depthwise filter has only 9 weights per channel. The paper reports that it was important to put very little or no weight decay (L2 regularization) on them.
  • Weaken regularization and data augmentation: Small models are more likely to underfit than to overfit. Reusing the training settings of large models as-is makes it harder to reach good accuracy.
  • Do not make the width multiplier too small: At α=0.25\alpha = 0.25, accuracy falls to 50.6%. Consider lowering the resolution first. For detection and segmentation, however, the task may make it hard to lower the input resolution.

Lower computation does not necessarily shorten actual latency by the same ratio. Depthwise convolutions involve many memory reads and writes relative to their computation, so depending on the hardware and library they may not speed up as much as the computation suggests. In measurements reported in the ShuffleNet paper (Snapdragon 820, single thread), 1.0 MobileNet-224 took 110.0 ms to process one 224×224 image. Measure the actual speed on the target device before choosing a model.

Table 1 of the paper lists the depthwise convolution of the last block as "stride 2", but since both its input and output are 7×7, the stride is actually 1. When building the network yourself, halve the height and width at only four places (where the size becomes 56, 28, 14, and 7).

Comparison with Other Models

The table below compares MobileNet with later models designed for low-compute devices, focusing on the shape of their blocks.

ModelBlock shapeResidual connectionCharacteristics
MobileNet (V1)Depthwise convolution → 1×1 convolutionNoSimple and easy to implement; size tunable with two multipliers
ShuffleNet1×1 grouped convolution → channel shuffle → depthwise → 1×1 grouped convolutionYesAlso cuts 1×1 computation, allowing more channels at the same cost
MobileNetV21×1 expansion → depthwise → 1×1 projection (no activation)Yes (between narrow layers)Inverted residuals and linear bottlenecks reach the same accuracy with less computation
MobileNetV3V2 block plus SE and h-swishYesStructure found by network search and tuned for latency on real devices

Rough guidelines for choosing:

  • To understand the mechanism or experiment with a simple structure: MobileNet (V1) is the simplest. With no residual connections or branches, it is also easy to quantize and port to dedicated hardware.
  • For higher accuracy at the same computation: Use MobileNetV2 or MobileNetV3. PyTorch's torchvision provides pretrained weights for both.
  • Under a very small compute budget (tens of millions of mult-adds): In the ShuffleNet paper, at about 40 million mult-adds, ShuffleNet had a 7.8-point lower error rate than MobileNet.

PyTorch example

Show code
python
import torch
import torch.nn as nn

"""
Build MobileNet (V1) as in Table 1 and Figure 3 of the paper.
torchvision includes MobileNetV2 and V3, but not V1.
"""


class DepthwiseSeparable(nn.Module):
    """3×3 depthwise conv → BN → ReLU → 1×1 conv → BN → ReLU (right side of Figure 3)"""

    def __init__(self, in_ch, out_ch, stride):
        super().__init__()
        self.depthwise = nn.Sequential(
            # groups=in_ch applies a separate filter to each channel (depthwise convolution)
            nn.Conv2d(in_ch, in_ch, 3, stride=stride, padding=1, groups=in_ch, bias=False),
            nn.BatchNorm2d(in_ch),
            nn.ReLU(inplace=True),
        )
        self.pointwise = nn.Sequential(
            nn.Conv2d(in_ch, out_ch, 1, bias=False),  # 1×1 mixes channels (pointwise convolution)
            nn.BatchNorm2d(out_ch),
            nn.ReLU(inplace=True),
        )

    def forward(self, x):
        return self.pointwise(self.depthwise(x))


class MobileNetV1(nn.Module):
    # (output channels, stride of the depthwise conv): the 13 blocks of Table 1
    # The "s2" of the last block in Table 1 is 7×7 → 7×7, so use stride 1
    CFG = [(64, 1), (128, 2), (128, 1), (256, 2), (256, 1), (512, 2),
           (512, 1), (512, 1), (512, 1), (512, 1), (512, 1), (1024, 2), (1024, 1)]

    def __init__(self, num_classes=1000, alpha=1.0):
        super().__init__()
        ch = lambda c: max(8, int(c * alpha))  # width multiplier α: scale the channels of every layer by α
        layers = [
            nn.Conv2d(3, ch(32), 3, stride=2, padding=1, bias=False),  # only the first layer is a standard conv
            nn.BatchNorm2d(ch(32)),
            nn.ReLU(inplace=True),
        ]
        in_ch = ch(32)
        for out_ch, stride in self.CFG:
            layers.append(DepthwiseSeparable(in_ch, ch(out_ch), stride))
            in_ch = ch(out_ch)
        self.features = nn.Sequential(*layers)
        self.pool = nn.AdaptiveAvgPool2d(1)          # global average pooling
        self.fc = nn.Linear(in_ch, num_classes)      # no activation; softmax is computed inside the loss function

    def forward(self, x):
        x = self.pool(self.features(x))
        return self.fc(torch.flatten(x, 1))


# The resolution multiplier ρ is set by the input image size (224, 192, 160, or 128)
model = MobileNetV1(num_classes=1000, alpha=0.75)
x = torch.randn(2, 3, 192, 192)  # 0.75 MobileNet-192
model.eval()                     # BN uses the mean and variance accumulated during training
with torch.no_grad():
    print(model(x).shape)        # torch.Size([2, 1000])

# No weight decay on depthwise convolution weights (Section 3.2 of the paper)
dw_params, other_params = [], []
for m in model.modules():
    if isinstance(m, nn.Conv2d) and m.groups == m.in_channels and m.groups > 1:
        dw_params += list(m.parameters())
    elif isinstance(m, (nn.Conv2d, nn.Linear, nn.BatchNorm2d)):
        other_params += list(m.parameters())
optimizer = torch.optim.RMSprop(
    [{"params": dw_params, "weight_decay": 0.0},
     {"params": other_params, "weight_decay": 4e-5}],
    lr=0.045, alpha=0.9, momentum=0.9,
)
model.train()                    # during training, BN uses the mini-batch mean and variance

FAQ

Q. How is MobileNet different from depthwise separable convolution?
A.

A depthwise separable convolution is a convolution building block, while MobileNet is an entire network built by stacking 13 of those blocks. Beyond the block itself, MobileNet defines the overall design: only the first layer is a standard convolution, height and width are halved by stride-2 depthwise convolutions, and the size is tuned with two multipliers, width and resolution.

Q. Which should be lowered first, the width multiplier or the resolution multiplier?
A.

In the paper's ImageNet results, α=0.75\alpha = 0.75 gave 68.4% accuracy at 325 million mult-adds, and a 160×160 input gave 67.2% at 290 million mult-adds. In both cases accuracy declines smoothly. To reduce the number of parameters (the size of the model file), lower the width multiplier; to reduce only computation while keeping the parameters, lower the resolution multiplier. For tasks such as detection where the input resolution is hard to lower, tune with the width multiplier.

Q. Does MobileNet have residual connections?
A.

No. MobileNet (V1) is simply a single stack of layers. Residual connections were introduced in MobileNetV2, in the form of "inverted residuals" that connect the layers with few channels.

References

  1. Howard, A. G., Zhu, M., Chen, B., Kalenichenko, D., Wang, W., Weyand, T., Andreetto, M., & Adam, H. (2017). MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications. arXiv:1704.04861.
  2. Zhang, X., Zhou, X., Lin, M., & Sun, J. (2018). ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices. CVPR 2018. arXiv:1707.01083.
  3. Sandler, M., Howard, A., Zhu, M., Zhmoginov, A., & Chen, L.-C. (2018). MobileNetV2: Inverted Residuals and Linear Bottlenecks. CVPR 2018. arXiv:1801.04381.