TL;DR
An MBConv block is the building block that efficient image networks for phones are made from. It first expands a thin feature map into more channels with a 1 by 1 convolution, applies a cheap per-channel spatial filter, optionally applies a squeeze-and-excitation step, and then projects back down to a thin map. When the input and output shapes match, it adds the input back at the end. The result is good accuracy for a small number of operations.
Builds on: Depthwise Separable Convolution, Residual Connection, Batch Normalization, Squeeze-and-Excitation Block · Leads to: EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks
Where it's used
Mobile image classifiers. The MobileNetV2 family uses this block, which its authors called an inverted residual with a linear bottleneck, to classify photos on phones with limited computation. The name "inverted" refers to the fact that the skip connection joins the thin maps, while the heavy middle works on wide maps.
Scaled-up efficient networks. The EfficientNet family builds on the same block. Its authors varied the depth, width and input resolution together, and used the MBConv block with an SE step as the unit that is repeated. The block is therefore the part of the design that gets copied and resized.
Feature extractors for detection and segmentation. Because the block keeps a small number of channels between blocks, the same design can serve as a backbone for detecting objects or segmenting images on devices where memory is tight.
How it works
Take an input with 2 channels, each a grid of pixels, and an expansion factor of 3. The expansion factor says how much wider the middle of the block is.
-
Expand with a 1 by 1 convolution. (A pointwise convolution.) Each pixel's 2 values are mixed into 6 new values by a 1 by 1 convolution. The middle now has 6 channels. The layer has 2 times 6 = 12 weights. Check: the spatial grid is unchanged; only the number of channels changes.
-
Filter each channel separately. A depthwise 3 by 3 convolution gives each of the 6 channels its own spatial filter, and channels do not mix. The layer has 9 times 6 = 54 weights. Check: the grid is still the same size if the padding keeps it, so each channel is smoothed or sharpened on its own.
-
Project back down with a 1 by 1 convolution. The 6 channels are mixed back into 2 channels. Here the block does not apply a nonlinearity, so the output stays linear in the middle. The layer has 6 times 2 = 12 weights. Check: the output has the same channel count as the input.
-
Add the input back. The input and output both have 2 channels and the same grid, so the block adds the original input to the output, as in a Residual Connection. Check: the skip connection is only possible because the shapes match. If they did not, the block would have no skip.
-
Count the total. The block has 12 plus 54 plus 12, which is 78 weights, ignoring the Batch Normalization and the optional SE step. A plain 3 by 3 convolution from 2 channels to 2 channels has 9 times 2 times 2 = 36 weights. Check: the block has more weights than one plain convolution at this width, but its spatial work is done on the wider middle.
flowchart LR A["Input, few channels"] --> B["1 by 1 expand, more channels"] B --> C["Depthwise 3 by 3, per channel"] C --> D["Optional squeeze-and-excitation"] D --> E["1 by 1 project, few channels"] A --> F["Add input back"] E --> F F --> G["Output"]
The math
Step 1 in symbols: the expansion
The expansion has weights E with shape (t C) by C, so it has t times C squared weights. In the toy, t = 3 and C = 2, so there are 3 times 2 times 2 = 12 weights. The 1 by 1 kernel mixes channels at each pixel and leaves the grid unchanged, as in a Pointwise (1x1) Convolution.
Step 2 in symbols: the depthwise filter
Each channel c has its own k by k kernel d, so the depthwise layer has k squared times t times C weights. In the toy, that is 9 times 6 = 54. Channel c of the output depends only on channel c of the input, which is what makes the layer cheap. This is the same idea as the depthwise half of a Depthwise Separable Convolution.
Step 3 in symbols: the projection
The projection has shape C by (t C), so it has 2 times 6 = 12 weights in the toy. No Rectified Linear Unit (ReLU) follows it, which is what the name "linear bottleneck" refers to: the thin output is a linear function of the wide middle, so no information is cut off by a bend at the narrow point.
Step 4 in symbols: the skip
Here s is the stride. With stride 2, the grid shrinks, so the shapes do not match and the skip is dropped.
Worked examples
The input has 2 channels, the expansion factor is 3, and the output has 2 channels.
- Expansion: 3 times 2 is 6 middle channels, so 2 times 6 gives 12 weights.
- Depthwise: 9 times 6 gives 54 weights.
- Projection: 6 times 2 gives 12 weights.
- Total: 12 plus 54 plus 12 is 78 weights.
- Interpretation: 78 weights for this block, compared with 36 for a plain 3 by 3 convolution at the same input and output widths. The block buys a wider, more expressive middle for extra weights.
The input has 24 channels and the expansion factor is 6.
- Middle width: 6 times 24 is 144 channels.
- Expansion weights: 24 times 144 is 3,456.
- Depthwise weights: 9 times 144 is 1,296.
- Projection weights: 144 times 24 is 3,456.
- Total: 3,456 plus 1,296 plus 3,456 is 8,208 weights.
- Plain 3 by 3 convolution, 24 to 24 channels: 9 times 24 times 24 is 5,184 weights.
- Interpretation: the block has about 1.6 times the weights of a plain convolution at this width (8,208 divided by 5,184 is about 1.58). The saving is not in weight count at this width; it is in the spatial filtering, which runs on 144 channels but costs only 9 weights per channel.
A block takes a 56 by 56 map with 24 channels and uses stride 2 in the depthwise layer, with 24 output channels.
- Input positions: 56 times 56 is 3,136.
- After stride 2 the grid is 28 by 28, so output positions: 28 times 28 is 784.
- Because the grid changed size, the skip connection is dropped, and the block output is the projection alone.
- Interpretation: the block halves each side of the grid, so the signal moves from fine to coarse positions, which is how efficient networks reduce resolution as they go deeper. The number of positions falls by a factor of 4.
Try it: a stride-1 block with 40 input channels and expansion factor 6 has the same grid and channel count at input and output. Does it keep the skip connection, and how many expansion weights does it have?
Answer: yes, it keeps the skip, because the grid and channel count match. The expansion has 40 times 240 weights, where 6 times 40 is 240, so 40 times 240 is 9,600 weights.
Common mistakes and tradeoffs
It is tempting to think that the block is cheap because it is called efficient. In fact at a fixed width it can have more weights than a plain convolution, as Example 1 shows. The saving comes from doing the spatial filtering per channel on a wide middle, so the cost depends on the chosen width and expansion.
It is tempting to think that the middle layer should have an activation after the projection, as in a standard bottleneck. In fact the authors of MobileNetV2 removed it, because a bend at the thin end destroys information when there are few channels. The output stays linear in the projection.
It is tempting to think that the skip connection can always be added. In fact it needs the same shape at input and output. A stride-2 block or a block that changes width has no skip.
When to use it: you need a good accuracy-per-operation trade-off on devices with little computation, and you can accept many small layers. When not to use it: you have a large GPU budget and want the simplest possible block, where a standard residual block may be easier to tune. Alternatives include the plain Residual Connection block and the Depthwise Separable Convolution on its own.
History
Through the mid-2010s, most image networks were built from standard convolutions with large widths, which are costly on phones. Depthwise separable convolutions were used to cut the cost. The next step was to notice that the thin layers between blocks should not carry a nonlinearity, and that the skip connection, popularised by ResNet, works better when it joins the thin maps.
Sandler and colleagues (2018) introduced the inverted residual with a linear bottleneck in MobileNetV2. Tan and Le (2019) built EfficientNet on MBConv blocks that include an SE step, and scaled the network's depth, width and resolution together.
Recap
- Expand: a 1 by 1 convolution widens the thin input.
- Filter: a depthwise convolution works on each wide channel separately.
- Optionally reweight with a squeeze-and-excitation step.
- Project: a 1 by 1 convolution narrows the output, with no nonlinearity after it.
- Add the input back only when the shapes match, which is what makes the block a Residual Connection.
Next, read how the block is scaled up in EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks.
Check yourself
QuestionRecall: why is the depthwise step cheaper than a standard 3 by 3 convolution on the same wide middle?Show answer
QuestionCompute: a block has 10 input channels and an expansion factor of 4. How many weights does the expansion step have?Show answer
QuestionWhy: why does the block have no nonlinearity after the final 1 by 1 projection?Show answer
QuestionApplied: an engineer uses an MBConv block with stride 2 and expects the skip connection to keep the input's full detail. What is wrong with that expectation?Show answer
Sources
- Sandler, Howard, Zhu, Zhmoginov and Chen, "MobileNetV2: Inverted Residuals and Linear Bottlenecks", arXiv:1801.04381 (2018). https://arxiv.org/abs/1801.04381
- Tan and Le, "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks", arXiv:1905.11946 (2019). https://arxiv.org/abs/1905.11946