MobileNetV2: Inverted Residuals and Linear Bottlenecks
- Publication
- CVPR 2018Conference
- First submitted to arXiv
- arXiv:1801.04381
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{lightweightmobilenetv22018,
title = {{MobileNetV2: Inverted Residuals and Linear Bottlenecks}},
author = {Mark Sandler and Andrew Howard and Menglong Zhu and Andrey Zhmoginov and Liang-Chieh Chen},
year = {2018},
eprint = {1801.04381},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1801.04381}
}
The first MobileNet split standard convolution into depthwise and pointwise operations, allowing image classification on mobile devices with fewer multiply-adds. MobileNetV2 asks a further question: can an already narrow feature representation survive another ReLU?
If a nonlinearity discards information in a narrow representation, making later layers wider cannot recover it. V2 therefore computes in a wider intermediate representation, keeps the final projection back to the narrow bottleneck linear, and connects the narrow ends with a residual shortcut.
Defining the Problem
Nonlinearity in Narrow Channels
A convolutional feature tensor has height , width , and channels. At one spatial position it becomes a -dimensional vector. The paper uses the intuition that useful features may lie near a lower-dimensional manifold: with a suitable representation, a narrow bottleneck may preserve task-relevant information. This is a design hypothesis, not a claim that arbitrary high-dimensional vectors project losslessly to a low-dimensional space.
ReLU maps negative values to zero. Try and : both become and can no longer be distinguished. MobileNetV2 uses ReLU6, which also clips values above 6. Applying such a nonlinearity in an overly narrow representation can lose distinctions that a later layer needs.
Look for the distinct points that ReLU folds together, not a rule that more dimensions are always lossless. The authors place nonlinearities in the expanded channels and leave the final 1×1 projection into the narrow bottleneck linear. A linear projection can still discard information, but it does not additionally clip many values to the same ReLU6 output.
Where Does the Residual Shortcut Connect?
A conventional bottleneck first narrows channels with a 1×1 convolution, applies a 3×3 in the narrow space, and restores channels with another 1×1. The shortcut joins the wider ends. MobileNetV2 reverses the width pattern: input and output are narrow, the middle expands before its depthwise 3×3, and the shortcut joins the narrow ends. Addition is possible only at stride 1 with equal input and output channels; downsampling or a channel change prevents a direct shortcut.
Solving the Problem
Inverted Residual and Linear Bottleneck
The unit is called an inverted residual with linear bottleneck. Trace a 14×14×64 input. A 1×1 convolution with expansion factor first creates 384 channels. Depthwise 3×3 then processes spatial information separately in each expanded channel. A final 1×1 projects back to 64 channels. The first two operations have BN and ReLU6; the final one has BN but no ReLU6. If stride is 1 and output remains 14×14×64, add the original input.
The first block with can omit the expansion layer. A stride-2 depthwise operation shrinks spatial size, so it has no equal-size shortcut. Paper Figure 3 compares shortcuts between narrow ends with classical residual designs; the imported diagram above shows the operation order.
Why Expand the Bottleneck?
Appendix A abstracts a vector transformation as . Here ; maps dimensions to ; ReLU acts elementwise; and projects back to . The in this model is the intermediate width, not necessarily the network's output channel count.
With , compression followed by ReLU makes it easier for distinct inputs to collapse together. With , extra intermediate channels offer more ways to preserve distinctions and more room for nonlinear expression. But alone does not make arbitrary invertible: rank, active channels, and the data distribution matter. Expansion lowers the risk of information collapse; the linear bottleneck avoids another clipping operation after projection.
From Block to Network
The initial standard 3×3 convolution changes 224×224×3 to 112×112×32. The first bottleneck row is ; the next is , whose first block downsamples to 56×56 and whose second stays at that size. Later rows produce 32, 64, 96, 160, and 320 channels before the final 1×1, pooling, and classifier. Section 4 calls these 19 bottleneck layers, but the Table 2 repeat counts sum to 17. The code below follows the table and instantiates 17 units; the two counts should not be treated as identical.
First implement one unit so the linear projection and shortcut condition are visible:
import torch.nn as nn
class InvertedResidual(nn.Module):
def __init__(self, inp, oup, stride, expand_ratio):
super().__init__()
if stride not in (1, 2):
raise ValueError("stride must be 1 or 2")
hidden_dim = int(inp * expand_ratio)
self.is_shortcut = stride == 1 and inp == oup
layers = []
if expand_ratio != 1:
layers.extend([
nn.Conv2d(inp, hidden_dim, 1, bias=False),
nn.BatchNorm2d(hidden_dim),
nn.ReLU6(),
])
layers.extend([
# Depthwise convolution in the expanded space.
nn.Conv2d(hidden_dim, hidden_dim, 3, stride, 1,
groups=hidden_dim, bias=False),
nn.BatchNorm2d(hidden_dim),
nn.ReLU6(),
# Linear projection: deliberately no activation after BN.
nn.Conv2d(hidden_dim, oup, 1, bias=False),
nn.BatchNorm2d(oup),
])
self.conv = nn.Sequential(*layers)
def forward(self, x):
out = self.conv(x)
return x + out if self.is_shortcut else out
Now connect the units according to Table 2. This is a feature extractor: it omits pooling and the 1000-class head. Channel counts use simple integer rounding rather than the multiples-of-eight rounding common in deployment implementations, so weights from those implementations may not load. The input size is not hard-coded here:
import torch.nn as nn
class MobileNetV2(nn.Module):
def __init__(self, width_mult=1.):
super(MobileNetV2, self).__init__()
if width_mult <= 0:
raise ValueError("width_mult must be positive")
# setting of inverted residual blocks
self.settings = [
# t, c, n, s
[1, 16, 1, 1],
[6, 24, 2, 2],
[6, 32, 3, 2],
[6, 64, 4, 2],
[6, 96, 3, 1],
[6, 160, 3, 2],
[6, 320, 1, 1],
]
# building first layer
input_channel = max(1, int(32 * width_mult))
self.first_layer = nn.Sequential(
nn.Conv2d(3, input_channel, 3, 2, 1, bias=False),
nn.BatchNorm2d(input_channel),
nn.ReLU6()
)
# building inverted residual blocks
layers = []
for t, c, n, s in self.settings:
output_channel = max(1, int(c * width_mult))
for i in range(n):
layers.append(
InvertedResidual(
input_channel,
output_channel,
stride=s if i == 0 else 1,
expand_ratio=t
)
)
input_channel = output_channel
self.layers = nn.Sequential(*layers)
# building last several layers
last_channel = int(1280 * width_mult) if width_mult > 1.0 else 1280
self.last_layer = nn.Sequential(
nn.Conv2d(input_channel, last_channel, 1, 1, 0, bias=False),
nn.BatchNorm2d(last_channel),
nn.ReLU6()
)
def forward(self, x):
x = self.first_layer(x)
x = self.layers(x)
x = self.last_layer(x)
return x
Discussion
ImageNet Classification and Phone Latency
In this table, baseline MobileNetV2 has 72.0% top-1, 3.4M parameters, 300M MAdds, and 75 ms. MobileNetV1 has 70.6%, 4.2M, 575M, and 113 ms. V2 is 1.4 percentage points more accurate, uses about 48% fewer multiply-adds, and has about 34% lower latency in the same phone column. The MobileNetV1 paper elsewhere reports 569M; this comparison uses the 575M printed in MobileNetV2 Table 4.
Around 300M MAdds, ShuffleNet 1.5× has 71.5%/292M, while MobileNetV2 has 72.0%/300M: V2 gains 0.5 point but costs 8M more MAdds, and no ShuffleNet CPU number is reported. Around 600M, MobileNetV2 1.4× has 74.7%/585M/143 ms against NASNet-A's 74.0%/564M/183 ms. V2 gains 0.7 point and has slightly more MAdds and parameters, with about 22% lower latency on this phone.
Other Tasks and Limits
The paper also uses V2 as a feature extractor for detection and segmentation. In COCO test-dev Table 6, V2+SSDLite has 22.1 mAP/0.8B MAdds/200 ms against V1+SSDLite's 22.2/1.3B/270 ms. V2 does not have higher mAP in these rows, though it uses fewer operations and is faster on the Pixel 1. In PASCAL VOC Table 7, the V2 variant using the penultimate feature map, no ASPP, output stride 16, and no multiscale/flipped testing reaches 75.32% mIoU/2.75B MAdds. These configurations are separate from the 300M-MAdd classification model.
Paper Figure 6 separately ablates bottleneck nonlinearity and shortcut placement. The authors report benefits from linear bottlenecks and narrow-end shortcuts. The memory savings also depend on the computation schedule in §5.1, so peak memory requires measurement with that schedule.
Conclusion
MobileNetV2 keeps nonlinearities in expanded intermediate channels, leaves the final narrow projection linear, and passes features across narrow-end shortcuts where shapes permit. In the paper's ImageNet and Pixel 1 settings, it improves accuracy while reducing multiply-adds and latency relative to V1. Downstream tasks require their own metrics and configurations.
For deployment, fix the width multiplier, input size, task head, and operator library first, then measure latency and memory on the target hardware. The paper gives a useful block design; realized gains depend on the complete model and runtime. Future work can keep exploring accuracy and generalization within these resource limits.