← Master Index
Vol. 07 Module 7.3 Lecture

MobileNet

Popular Vision Models

How This Lesson Fits the Module

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.

Standard conv (VGG/ResNet) — every filter mixes all channels; expensive MobileNet (2017) — depthwise + pointwise split; ~8× cheaper V2/V3 — inverted residuals, SE blocks, NAS-tuned for latency

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.
Definition — Depthwise Separable Convolution

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.

ModelYearParamsKey innovation
MobileNetV12017~4.2MDepthwise separable conv
MobileNetV22018~3.5MInverted residuals + linear bottleneck
MobileNetV3-Small2019~2.5MNAS + Squeeze-Excitation + h-swish
MobileNetV3-Large2019~5.4MNAS-tuned for latency

Depthwise Separable Conv in PyTorch

import torch import torch.nn as nn from torchvision.models import mobilenet_v3_large, MobileNet_V3_Large_Weights # The building block, hand-written: class DepthwiseSeparable(nn.Module): def __init__(self, in_ch, out_ch, stride=1): super().__init__() self.depthwise = nn.Conv2d(in_ch, in_ch, 3, stride, 1, groups=in_ch, bias=False) # per-channel self.pointwise = nn.Conv2d(in_ch, out_ch, 1, bias=False) # mix channels self.bn1, self.bn2 = nn.BatchNorm2d(in_ch), nn.BatchNorm2d(out_ch) self.relu = nn.ReLU6(inplace=True) def forward(self, x): x = self.relu(self.bn1(self.depthwise(x))) return self.relu(self.bn2(self.pointwise(x))) # In practice, load a pretrained MobileNetV3: weights = MobileNet_V3_Large_Weights.IMAGENET1K_V2 model = mobilenet_v3_large(weights=weights) model.classifier[3] = nn.Linear(model.classifier[3].in_features, 10) print(sum(p.numel() for p in model.parameters())) # ~4.3M after head swap
Module 7.1 Tie-In The 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
Common Misconception: “Depthwise separable convolution is just a smaller normal convolution.”

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.

Critical Mistake — Ignoring the Deployment Target

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

  1. Short Answer: What two steps make up a depthwise separable convolution? Answer: Depthwise conv + pointwise (1×1) conv.
  2. True/False: MobileNet is designed for mobile and edge deployment. Answer: True.
  3. Multiple Choice: The depthwise step does what? (a) mixes channels, (b) filters each channel separately, (c) applies softmax, (d) pools. Answer: (b).
  4. Short Answer: Roughly how much cheaper is depthwise separable vs standard 3×3 conv? Answer: About 8–9×.
  5. True/False: MobileNetV2 introduced inverted residual blocks. Answer: True.
  6. Multiple Choice: The pointwise conv uses what kernel size? (a) 1×1, (b) 3×3, (c) 5×5, (d) 7×7. Answer: (a).
  7. Short Answer: Which PyTorch argument makes a conv depthwise? Answer: groups=in_channels.
  8. True/False: MobileNet reaches higher peak accuracy than ResNet-152. Answer: False (it trades accuracy for speed).
  9. Multiple Choice: To further speed MobileNet on-device, apply: (a) more dropout, (b) INT8 quantization, (c) larger images, (d) more FC layers. Answer: (b).
  10. 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.
Trainer’s Guide

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.

Progress Backbones covered from LeNet to MobileNet. Next we apply these ideas to a task backbone: real-time object detection. Continue to YOLO.