Search

Search papers and lessons

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision

Andrew G. Howard, Menglong Zhu, Bo Chen et al. · 2017

MobileNet builds image classifiers from depthwise separable convolutions and two shrink knobs, trading a little accuracy for much less computation so that they run on phones.

On this page

  • Colour = topic mix
  • Calculus
  • Neural network basics
  • Discrete math
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

MobileNet is a family of image classifiers built for phones and other small devices. Its main building block, the depthwise separable convolution, splits one expensive filtering step into two cheap ones. Two simple settings, a width multiplier and a resolution multiplier, let a builder pick a model that fits a latency or size budget. On ImageNet the full model reaches 70.6 percent top-1 accuracy with 569 million multiply-adds, where a comparable VGG16 needs 15300 million.

Builds on: Depthwise Separable Convolution, Convolutional Neural Network, Batch Normalization · Leads to: the later mobile architectures that keep depthwise separable blocks, and the object detectors and face models that use MobileNet as a backbone (see Object Detection)

Why it mattered

The paper turned a building block from an earlier network into a documented, tunable family that others could deploy. Its authors describe use on robots, self-driving cars and augmented reality, where recognition must run in a timely way on a limited platform. In the paper's experiments the same backbone is used for fine-grained dog recognition, large-scale photo geolocation with a PlaNet variant, face attributes, face embeddings, and object detection on COCO.

Its influence is in the design pattern: a small set of global knobs that let one architecture be resized without redesign. The paper's own result is that the depthwise separable block costs about 1 percent accuracy on ImageNet compared with a full-convolution version of the same network (Table 4).

History

Depthwise separable convolutions came from earlier work. The paper credits their first introduction to a 2014 thesis by Sifre (reference 26), and notes that Inception models later used them in the first few layers to cut computation. The paper places itself among other small-network efforts, including Flattened networks, Factorized networks, Xception, and SqueezeNet, and it also reviews approaches that compress pretrained networks, such as Pruning, Quantization and distillation. It notes that the Factorized Networks it cites were developed independently of this paper.

The problem

The trend in image classification through 2016 was toward deeper and more complicated networks to gain accuracy. The paper observes that these gains do not make networks smaller or faster, and that many real applications have only a small computational budget. A deep network that wins the ImageNet contest may be too slow to run on a phone's processor in real time.

Two questions follow. How can a convolutional layer do the same job with far fewer multiply-adds (the basic arithmetic step the paper uses as its cost measure)? And once the layer is cheap, how can a builder pick the right size of network for a given budget without designing a new architecture each time?

How it works

We trace one tiny layer from start to finish. Assume a 4×44 \times 4 input with M=2M = 2 channels, a 3×33 \times 3 kernel, and N=3N = 3 output channels. Stride one and padding keep the spatial size at 4×44 \times 4.

  1. Input. The layer receives a 4×4×24 \times 4 \times 2 feature map. Each position has two numbers, one per channel.
  2. Depthwise step. Each input channel gets its own 3×33 \times 3 filter, applied to that channel alone. The output is still 4×4×24 \times 4 \times 2: two filtered channels that have not yet been combined. Check: 2 filters, 2 channels, 2 outputs.
  3. Pointwise step. A [[pointwise-convolution|1×11 \times 1 convolution]] then mixes the two filtered channels at each position. It has 3 filters, one per output channel, and each filter has 2 weights, one for each input channel. The output is 4×4×34 \times 4 \times 3. Check: the spatial size is unchanged, and the depth is now 3.
  4. Normalise and activate. Batch normalisation and a Rectified Linear Unit (ReLU) follow each of the two steps, as the paper specifies for every layer.
  5. Count the work. The standard convolution would need one 3×33 \times 3 kernel for each of the 2×32 \times 3 channel pairs, so the cost is larger: for this tiny layer, 2.25 times larger than the two-step version. The two-step version does the spatial filtering once per input channel and the mixing once per pair of channels.

Here is the flow of one block in the full network:

flowchart LR
  A["Input feature map M channels"] --> B["Depthwise 3x3 one filter per channel"]
  B --> C["Batch norm and ReLU"]
  C --> D["Pointwise 1x1 mixes channels into N outputs"]
  D --> E["Batch norm and ReLU"]
  E --> F["Output feature map N channels"]

Check: for this tiny layer the two-step version performs 3⋅3⋅2⋅4⋅4=2883 \cdot 3 \cdot 2 \cdot 4 \cdot 4 = 288 multiply-adds in the depthwise step and 2⋅3⋅4⋅4=962 \cdot 3 \cdot 4 \cdot 4 = 96 in the pointwise step. The standard version performs 3⋅3⋅2⋅3⋅4⋅4=8643 \cdot 3 \cdot 2 \cdot 3 \cdot 4 \cdot 4 = 864. The worked examples below repeat this with the paper's numbers.

The full network, in Table 1, follows the same pattern. It starts with one ordinary strided 3×33 \times 3 convolution on a 224×224×3224 \times 224 \times 3 image, then stacks 13 depthwise and pointwise pairs, with some depthwise layers strided to halve the resolution. A final average pool and a fully connected layer give 1000 classes. Counting depthwise and pointwise convolutions separately, the paper says the model has 28 layers.

The two shrink knobs come next. The width multiplier α\alpha thins every layer by the same fraction, and the resolution multiplier ρ\rho shrinks the input image size. Both are set once, before training, and the model is then trained from scratch.

The math

Let a layer take an input feature map F\mathbf{F} of size DF×DF×MD_F \times D_F \times M and produce an output G\mathbf{G} of size DF×DF×ND_F \times D_F \times N. The kernel size is DKD_K. The paper assumes stride one and padding, so the output has the same spatial size as the input.

Step 2 in symbols: the standard convolution cost

A standard convolution uses a kernel K\mathbf{K} of size DK×DK×M×ND_K \times D_K \times M \times N and costs

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

multiply-adds. Every input channel is combined with every output channel at every spatial position.

Step 3 in symbols: depthwise plus pointwise

The depthwise step uses one kernel K^\hat{\mathbf{K}} of size DK×DK×MD_K \times D_K \times M and costs

DK⋅DK⋅M⋅DF⋅DF.D_K \cdot D_K \cdot M \cdot D_F \cdot D_F.

The pointwise step is a 1×11 \times 1 convolution from MM channels to NN channels and costs

M⋅N⋅DF⋅DF.M \cdot N \cdot D_F \cdot D_F.

The depthwise separable convolution costs their sum.

Step 5 in symbols: the ratio

Divide the separable cost by the standard cost. The factor MDF2M D_F^2 appears in every term and cancels, leaving

DK2MDF2+MNDF2DK2MNDF2=1N+1DK2.\frac{D_K^2 M D_F^2 + M N D_F^2}{D_K^2 M N D_F^2} = \frac{1}{N} + \frac{1}{D_K^2}.

For the 3×33 \times 3 kernels the paper uses, DK2=9D_K^2 = 9, so the ratio is 1N+19\frac{1}{N} + \frac{1}{9}. For large NN this approaches 19\frac{1}{9}, which is the paper's "8 to 9 times less computation."

The width multiplier

With width multiplier α∈(0,1]\alpha \in (0, 1], every layer uses αM\alpha M input channels and αN\alpha N output channels. The cost becomes

DK2⋅αM⋅DF2+αM⋅αN⋅DF2.D_K^2 \cdot \alpha M \cdot D_F^2 + \alpha M \cdot \alpha N \cdot D_F^2.

The cost falls by roughly α2\alpha^2. The typical settings are 1, 0.75, 0.5 and 0.25.

The resolution multiplier

With resolution multiplier ρ∈(0,1]\rho \in (0, 1], the feature maps have ρDF\rho D_F width and height. The cost becomes

DK2⋅αM⋅ρ2DF2+αM⋅αN⋅ρ2DF2,D_K^2 \cdot \alpha M \cdot \rho^2 D_F^2 + \alpha M \cdot \alpha N \cdot \rho^2 D_F^2,

so the cost falls by ρ2\rho^2. The paper sets ρ\rho implicitly through the input size 224, 192, 160 or 128.

Worked examples

Example
Example 1: the tiny layer by hand

Use the layer from How it works: DK=3D_K = 3, M=2M = 2, N=3N = 3, DF=4D_F = 4.

  1. The standard cost is DK⋅DK⋅M⋅N⋅DF⋅DFD_K \cdot D_K \cdot M \cdot N \cdot D_F \cdot D_F.
  2. Substitute: 3⋅3⋅2⋅3⋅4⋅43 \cdot 3 \cdot 2 \cdot 3 \cdot 4 \cdot 4.
  3. Multiply the first four: 3⋅3=93 \cdot 3 = 9, then 9⋅2=189 \cdot 2 = 18, then 18⋅3=5418 \cdot 3 = 54.
  4. Multiply by 4⋅4=164 \cdot 4 = 16: 54⋅16=86454 \cdot 16 = 864.
  5. The separable cost is DK2MDF2+MNDF2=9⋅2⋅16+2⋅3⋅16D_K^2 M D_F^2 + M N D_F^2 = 9 \cdot 2 \cdot 16 + 2 \cdot 3 \cdot 16.
  6. The first term is 288288 and the second is 9696. Their sum is 384384.
  7. The ratio is 384/864≈0.444384 / 864 \approx 0.444. The formula gives 13+19=49≈0.444\frac{1}{3} + \frac{1}{9} = \frac{4}{9} \approx 0.444, so the two agree.

Interpretation: even in this tiny layer the separable version does a bit less than half the work.

Example
Example 2: the paper's own layer, Table 3

Table 3 takes one layer with DF=14D_F = 14, M=N=512M = N = 512, DK=3D_K = 3, and reports its cost in millions of multiply-adds.

  1. Standard cost: 9⋅512⋅512⋅14⋅149 \cdot 512 \cdot 512 \cdot 14 \cdot 14. First 9⋅512⋅512=2,359,2969 \cdot 512 \cdot 512 = 2{,}359{,}296. Then 2,359,296⋅196=462,422,0162{,}359{,}296 \cdot 196 = 462{,}422{,}016, which is 462 million. This matches the table.
  2. Separable cost, depthwise term: 9⋅512⋅196=903,1689 \cdot 512 \cdot 196 = 903{,}168.
  3. Separable cost, pointwise term: 512⋅512⋅196=51,380,224512 \cdot 512 \cdot 196 = 51{,}380{,}224.
  4. Their sum is 52,283,39252{,}283{,}392, which is 52.3 million. The table reports 52.3.
  5. Apply α=0.75\alpha = 0.75: the cost is 0.75⋅903,168+0.5625⋅51,380,224=677,376+28,901,376=29,578,7520.75 \cdot 903{,}168 + 0.5625 \cdot 51{,}380{,}224 = 677{,}376 + 28{,}901{,}376 = 29{,}578{,}752, which is 29.6 million. The table reports 29.6.
  6. Apply ρ=0.714\rho = 0.714, so ρ2≈0.5098\rho^2 \approx 0.5098: 29.58⋅0.5098≈15.0829.58 \cdot 0.5098 \approx 15.08 million. The table reports 15.1.

Interpretation: each knob multiplies the cost by a predictable factor, and the paper's table can be reproduced from the formulas alone.

Example
Example 3: choosing a model for a budget

Table 6 and Table 7 give the accuracy and cost of several MobileNets on ImageNet. Suppose an app can spend about 150 million multiply-adds per image. Two options are 0.5 MobileNet-224 (149 million, 63.7 percent) and 1.0 MobileNet-128 (186 million, 64.4 percent).

  1. The 1.0 MobileNet-128 costs 186 million, which is above the 150 million budget.
  2. The 0.5 MobileNet-224 costs 149 million, which fits.
  3. Compare accuracies: 63.7 percent for the one that fits.
  4. Compare with the full model, 1.0 MobileNet-224, at 569 million and 70.6 percent. It costs 569/149≈3.8569 / 149 \approx 3.8 times as much.
  5. The accuracy drop from the full model is 70.6−63.7=6.970.6 - 63.7 = 6.9 percentage points.

Try it: the smallest model in Table 6, 0.25 MobileNet-224, costs 41 million and reaches 50.6 percent. How many times less compute is that than the full model, and how many accuracy points does it give up? Answer: 569/41≈13.9569 / 41 \approx 13.9 times less compute, and 70.6−50.6=20.070.6 - 50.6 = 20.0 points lost.

Results

All numbers come from the paper's tables. The paper measures cost in multiply-adds, not in measured phone latency, and the text does not report on-device timings.

  • Depthwise separable versus full convolution (Table 4). The full-convolution MobileNet gets 71.7 percent on ImageNet at 4866 million multiply-adds and 29.3 million parameters. The separable MobileNet gets 70.6 percent at 569 million and 4.2 million parameters. The accuracy cost is 1.1 points.
  • Thinner versus shallower (Table 5). At similar cost, the 0.75 MobileNet (68.4 percent, 325 million, 2.6 million parameters) beats a shallower model with the middle separable layers removed (65.3 percent, 307 million, 2.9 million parameters) by 3.1 points.
  • Width multiplier (Table 6). Accuracy is 70.6, 68.4, 63.7 and 50.6 percent for α\alpha equal to 1, 0.75, 0.5 and 0.25. The multiply-adds are 569, 325, 149 and 41 million. The text says accuracy "drops off smoothly until the architecture is made too small at α=0.25\alpha = 0.25."
  • Resolution multiplier (Table 7). Accuracy is 70.6, 69.1, 67.2 and 64.4 percent at input sizes 224, 192, 160 and 128. The multiply-adds are 569, 418, 290 and 186 million.
  • Comparison with large models (Table 8). The full MobileNet gets 70.6 percent at 569 million, against 71.5 percent for VGG16 at 15300 million and 138 million parameters. Against GoogleNet it gets 70.6 against 69.8 at 1550 million. Table 9 gives the smaller 0.50 MobileNet-160 at 60.2 percent, 76 million multiply-adds and 1.32 million parameters, against 57.2 percent for AlexNet at 720 million and 60 million parameters. The paper's text describes the AlexNet gap as 4 percent. The table numbers give 3.0 points, so use the table.
  • Object detection (Table 13). Under SSD 300, MobileNet gets 19.3 percent mAP at 1.2 billion multiply-adds and 6.8 million parameters. Inception V2 gets 22.0 percent at 3.8 billion. Under Faster-RCNN with 600 input, MobileNet gets 19.8 percent at 30.5 billion and VGG gets 25.7 percent at 149.6 billion.
  • Geolocation (Table 11). The MobileNet version of PlaNet matches or nearly matches the Inception-based PlaNet at the continent level (79.3 against 77.6 percent) and at the city level (31.7 against 31.7 percent), and falls behind at the country level (60.3 against 64.0 percent).

Common mistakes and tradeoffs

It is tempting to think that fewer multiply-adds always means faster code. The paper says the cost of unstructured sparse operations is not usually lower until sparsity is very high, and that its model places most of its work in dense 1×11 \times 1 convolutions, which map well to fast matrix multiplication. Speed depends on the implementation as well as the count. It is tempting to think a depthwise separable block is free. In fact Table 4 shows a 1.1 point accuracy cost on ImageNet. It is tempting to think a width multiplier can be applied to a trained model. In fact the paper says the thinner models must be trained from scratch.

When to use MobileNet: a vision task with a fixed compute or size budget on phones, embedded boards or robots, where a few points of accuracy can be traded for a large cut in cost. When not to use it: when the top accuracy matters more than cost, since VGG16 is more accurate than the full MobileNet in Table 8 (71.5 against 70.6 percent), or when the platform is fast enough for a larger model. Alternatives in the paper include Pruning and Quantization, which compress a trained network, and distillation, which the paper says is complementary and uses for face attributes.

Reading guide

  1. Abstract and Section 1. The motivation: latency and size on limited platforms, and the two global knobs. Needs nothing beyond Convolutional Neural Network.
  2. Section 2 (Prior Work). Read the short survey, which places the paper among compression and small-network methods. Needs Knowledge Distillation and Pruning at the level of "shrinking a trained network".
  3. Section 3.1 (Depthwise Separable Convolution). The core idea and the cost formulas. Needs Depthwise Separable Convolution and Pointwise (1x1) Convolution. Work the formulas in the Math section.
  4. Section 3.2 (Network Structure and Training). Table 1 and Table 2. Needs Batch Normalization, Rectified Linear Unit (ReLU), Global Average Pooling and Softmax. Note the RMSprop training described here, from RMSProp.
  5. Sections 3.3 and 3.4 (Multipliers). Read the two formulas and Table 3. Needs nothing new.
  6. Section 4 (Experiments). Tables 4 to 9 for ImageNet, then Tables 10 to 14 for the applications. The applications use Transfer Learning, Object Detection and Knowledge Distillation, so read those first if they are new.
  7. Section 5 (Conclusion). Short.

Check yourself

QuestionIn one or two sentences, why does a depthwise separable convolution cost less than a standard convolution with the same input and output sizes?Show answer

A standard convolution filters and combines channels in one step, so every pair of input and output channels gets its own spatial kernel. The separable version filters each input channel once with a small kernel and then combines the channels with a cheap 1×11 \times 1 convolution. The filtering cost scales with the number of input channels only, and the combining cost is small.

QuestionA layer has DK=3D_K = 3, M=64M = 64, N=128N = 128 and DF=28D_F = 28. Compute the standard cost and the depthwise separable cost in multiply-adds, and give the ratio to two decimal places.Show answer

Standard: 9⋅64⋅128⋅784=57,802,7529 \cdot 64 \cdot 128 \cdot 784 = 57{,}802{,}752. Separable: the depthwise term is 9⋅64⋅784=451,5849 \cdot 64 \cdot 784 = 451{,}584 and the pointwise term is 64⋅128⋅784=6,422,52864 \cdot 128 \cdot 784 = 6{,}422{,}528, for a total of 6,874,1126{,}874{,}112. The ratio is 6,874,112/57,802,752≈0.126{,}874{,}112 / 57{,}802{,}752 \approx 0.12. The formula 1128+19≈0.12\frac{1}{128} + \frac{1}{9} \approx 0.12 agrees.

QuestionThe width multiplier and the resolution multiplier both reduce cost. Why does the width multiplier reduce cost by roughly α2\alpha^2 while the resolution multiplier reduces it by ρ2\rho^2?Show answer

The width multiplier scales both the input and the output channel counts of every layer, and the cost term is proportional to the product of these two counts, so scaling each by α\alpha scales the cost by α2\alpha^2 overall. The resolution multiplier scales only the width and height of the feature maps, and the cost is proportional to the spatial area, so scaling width and height by ρ\rho scales the area by ρ2\rho^2.

QuestionTable 3 says a 14×14×51214 \times 14 \times 512 layer costs 462 million multiply-adds as a standard convolution. Using only that figure and the separable ratio from the paper's formula, estimate the separable cost and check it against the table.Show answer

The ratio is 1N+1DK2=1512+19≈0.1131\frac{1}{N} + \frac{1}{D_K^2} = \frac{1}{512} + \frac{1}{9} \approx 0.1131. Then 462.4×0.1131≈52.3462.4 \times 0.1131 \approx 52.3 million, which matches the separable row of Table 3. (The exact standard cost is 462.4 million, so the rounded 462 gives 52.2 instead.)

QuestionAn app has a budget of 60 million multiply-adds per image and needs the highest ImageNet accuracy it can get within that budget. Using only Tables 6 and 7, which model should it use and why?Show answer

From Table 6 and 7, the candidates under 60 million are the 0.25 MobileNet-224 at 41 million and 50.6 percent, and the 1.0 MobileNet-128 at 186 million (above budget, so no). The 0.25 model is the only option under 60 million in those tables, so the app should use it. Its accuracy is limited, so if the budget could be raised, a model such as 0.5 MobileNet-224 at 149 million and 63.7 percent would be a better choice.

Sources

  • Howard, Zhu, Chen, Kalenichenko, Wang, Weyand, Andreetto, Adam, "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications," arXiv:1704.04861, 2017. https://arxiv.org/abs/1704.04861
  • Chollet, "Xception: Deep Learning with Depthwise Separable Convolutions," arXiv:1610.02357, 2016. https://arxiv.org/abs/1610.02357

Read the full paper

Andrew G. Howard, Menglong Zhu, Bo Chen et al., 2017. arXiv:1704.04861