EfficientNet optimized accuracy per FLOP on servers. But phones, drones, and embedded chips need models that run in milliseconds on tiny batteries. MobileNet (Google, 2017–2019) is purpose-built for that world. Its key trick—depthwise separable convolution—cuts convolution cost by roughly 8–9× with minimal accuracy loss.
Learning Objectives
By the end of this lesson, students should be able to:
- Explain depthwise separable convolution as depthwise + pointwise steps.
- Quantify the compute savings versus a standard convolution.
- Describe the inverted residual (MBConv) block in MobileNetV2.
- Use the width and resolution multipliers to trade accuracy for speed.
- Load MobileNetV3 from
torchvision.models. - Choose MobileNet vs heavier backbones based on deployment constraints.
A depthwise separable convolution factorizes a standard convolution into two cheaper steps: (1) a depthwise conv applies one filter per input channel (spatial filtering, no channel mixing), then (2) a pointwise 1×1 conv combines channels. This costs roughly 1/N + 1/k² of a standard conv (N = output channels, k = kernel size).
The Cost Savings
A standard 3×3 conv with Din input and Dout output channels over an H×W map costs H·W·Din·Dout·9. The depthwise-separable version costs H·W·Din·9 (depthwise) + H·W·Din·Dout (pointwise). For a typical Dout=256, that is about 8–9× fewer multiply-adds.
| Model | Year | Params | Key innovation |
|---|---|---|---|
| MobileNetV1 | 2017 | ~4.2M | Depthwise separable conv |
| MobileNetV2 | 2018 | ~3.5M | Inverted residuals + linear bottleneck |
| MobileNetV3-Small | 2019 | ~2.5M | NAS + Squeeze-Excitation + h-swish |
| MobileNetV3-Large | 2019 | ~5.4M | NAS-tuned for latency |
Depthwise Separable Conv in PyTorch
groups=in_ch argument turns a normal convolution into a depthwise one—each filter touches a single channel. The 1×1 pointwise conv then rebuilds cross-channel information.MobileNet Strengths
- Tiny (2–5M params) and fast
- Runs on phones and microcontrollers
- Low memory and energy use
- Adjustable via width multiplier
MobileNet Trade-offs
- Lower peak accuracy than big backbones
- Depthwise convs can be bandwidth-bound
- Less capacity for very fine tasks
- Needs careful quantization for best speed
Reality: It is a factorization, not a size reduction. It splits one operation into spatial filtering (depthwise) and channel mixing (pointwise). The result approximates a standard conv at a fraction of the cost—a different computation, not merely fewer channels.
MobileNet’s advantage is latency and energy on-device. Benchmarking it only on a data-center GPU (where big models also run fast) hides its value. Always measure on the actual target hardware—and combine with INT8 quantization for maximum speed.
Knowledge Check
- Short Answer: What two steps make up a depthwise separable convolution? Answer: Depthwise conv + pointwise (1×1) conv.
- True/False: MobileNet is designed for mobile and edge deployment. Answer: True.
- Multiple Choice: The depthwise step does what? (a) mixes channels, (b) filters each channel separately, (c) applies softmax, (d) pools. Answer: (b).
- Short Answer: Roughly how much cheaper is depthwise separable vs standard 3×3 conv? Answer: About 8–9×.
- True/False: MobileNetV2 introduced inverted residual blocks. Answer: True.
- Multiple Choice: The pointwise conv uses what kernel size? (a) 1×1, (b) 3×3, (c) 5×5, (d) 7×7. Answer: (a).
- Short Answer: Which PyTorch argument makes a conv depthwise? Answer: groups=in_channels.
- True/False: MobileNet reaches higher peak accuracy than ResNet-152. Answer: False (it trades accuracy for speed).
- Multiple Choice: To further speed MobileNet on-device, apply: (a) more dropout, (b) INT8 quantization, (c) larger images, (d) more FC layers. Answer: (b).
- Short Answer: Name one thing to measure before claiming MobileNet is “fast.” Answer: Latency/energy on the target device.
Key Takeaways
- MobileNet factorizes convolution into depthwise + pointwise steps for ~8× savings.
- V2 adds inverted residuals; V3 adds NAS, Squeeze-Excitation, and h-swish.
- Width and resolution multipliers tune the accuracy/latency trade-off.
- It targets on-device latency and energy, not peak server accuracy.
- Next: we shift from backbones to tasks—real-time detection with YOLO.
Exercise: Have students compute multiply-adds for a standard 3×3×256 conv vs its depthwise-separable version on a 56×56 map and verify the ~8× savings by hand.
Demo: Export MobileNetV3 to ONNX/TFLite and run it on a phone or Raspberry Pi to make the “runs anywhere” claim tangible.