Foundations to Frontier
Tests
E. Deep Learning › E7 CNN Building Blocks

Depthwise Separable Convolution

A depthwise separable convolution splits a standard convolution into two cheap steps: a depthwise convolution that filters each input channel with its own small spatial kernel, and a pointwise 1×1 convolution that mixes channels. For 3×3 kernels it needs about 8–9 times fewer weights and operations, which is why MobileNet, Xception and EfficientNet are built from it. This page covers the factorisation, its cost ratio 1/C_out + 1/k², what it cannot represent, and how to spend the savings. In the exercises you show the separable layer equals a standard convolution whose spatial filters are shared across outputs up to scale, then find that at an equal weight budget a separable layer affords 135 output channels against 16 and gives better random features (90% against 73% accuracy).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Filter space and mix channels separately

A standard convolution does two jobs at once: it looks at a spatial neighbourhood and it combines all input channels, with a separate 3 × 3 filter for every pair of input and output channels. A depthwise separable convolution does the jobs one after the other: first each channel gets its own small spatial filter (depthwise), then a 1×1 convolution mixes the channels (pointwise). It gives up some flexibility but costs a fraction as much.

CNN building blocks
parameters (no bias): standard 73,728 · grouped (g = 1) 73,728 · depthwise separable 8,768 (8.4× fewer) · multiply–adds per image: 231.2 M vs 27.5 M
Deep-learning "convolution" slides a small learned kernel over the input (no flip). Stride shrinks the output, padding preserves borders, dilation spreads the kernel to see further without more weights. Pooling summarises windows. Stacking layers grows the receptive field. Depthwise-separable and grouped convolutions cut cost by not connecting every input channel to every output channel. Transposed convolution upsamples, but uneven kernel overlap leaves checkerboard patterns. Squeeze-and-excitation rescales whole channels by gates computed from their global averages; CBAM adds a per-pixel spatial gate. (Here the gates are fixed functions of the averages so you can see their effect; in a network the excitation is learned.)
Why engineers care

Separable convolutions made real-time vision possible on phones, drones and microcontrollers: MobileNet, Xception, EfficientNet and many embedded detectors use them. For the same compute, a network can be wider or deeper, which often more than compensates for the restriction.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The depthwise step filters…
  2. 2. The pointwise step is…
  3. 3. Separable convolutions are the basis of…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Depthwise: C_in filters of size k × k, one per channel: C_in·k² weights.
  • Pointwise: C_in·C_out weights.
  • Standard: C_in·C_out·k² weights.
  • Ratio: (C_in·k² + C_in·C_out)/(C_in·C_out·k²) = 1/C_out + 1/k². For C_out = 256, k = 3: 0.115, about 8.7 times cheaper. Multiply–adds scale the same way: H·W·(C_in·k² + C_in·C_out).
  • Example: 64 → 128 channels with 3 × 3 kernels: separable 576 + 8192 = 8768 weights; standard 73 728.
  • Equal budget: with 2304 weights and 16 input channels, a standard 3 × 3 layer affords 16 output channels; a separable layer affords (2304 − 144)/16 = 135.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Separable weights for 64 → 128, 3 × 3:
  2. 2. Cost ratio for 256 outputs, 3 × 3:
  3. 3. Output channels for 2304 weights, 16 inputs, separable:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 20 minUndergraduate students and practising engineers.

Separable convolutions in code

Exercise 1.

  • Depthwise then pointwise equalled a standard convolution with kernel K[o, c] = P[o, c]·D[c].
  • For each input channel, the separable layer’s six spatial filters had rank 1 (all scaled copies of one filter), against rank 6 for a general kernel.
  • The cost ratio for 256 output channels was 0.115.

Practice.

  • In PyTorch: nn.Conv2d(C, C, 3, padding=1, groups=C) followed by nn.Conv2d(C, C_out, 1).
  • MobileNet places normalisation and activation after both steps; MobileNetV2 inverts the order inside a residual block (E8-16).
  • On GPUs the depthwise step has low arithmetic intensity and may not speed up as much as the operation count suggests; on mobile CPUs and NPUs it usually does.
sep = torch.nn.Sequential(torch.nn.Conv2d(64, 64, 3, padding=1, groups=64, bias=False), torch.nn.BatchNorm2d(64), torch.nn.ReLU(),
                          torch.nn.Conv2d(64, 128, 1, bias=False), torch.nn.BatchNorm2d(128), torch.nn.ReLU())
🐍 Exercise 1: separable equals a constrained standard convolution
Implement depthwise, pointwise and standard convolutions, show depthwise-then-pointwise is a standard convolution with a factorised kernel, and compute the cost ratio.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A depthwise conv in PyTorch uses…
  2. 2. On GPUs, depthwise convs may be slower than expected because of…
  3. 3. The separable kernel for output o and input c is…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What is lost. A standard layer has an independent spatial filter for every (output, input) pair. A separable layer uses one spatial filter per input channel, shared by all outputs up to a scalar. It is a constrained subset of standard convolutions, so it can represent fewer functions per layer.

Why it works anyway. Chollet (2017) argued, with Xception, that cross-channel and spatial correlations in feature maps are largely decoupled, so mapping them separately loses little. The saved compute can buy more channels or layers, which matters more.

Equal budgets. At a fixed number of weights, a separable layer can be about k² times wider. More, cheaper features often help, as exercise 2 shows with random features; with trained networks MobileNet reached near-VGG accuracy with about 30 times less computation.

Related factorisations. Spatially separable kernels (k × 1 then 1 × k), grouped convolutions (E7-7), and low-rank tensor decompositions are other ways to trade flexibility for cost.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Xception's premise is that spatial and channel correlations are…
  2. 2. At equal weights, a separable layer can be about…
  3. 3. A k × 1 then 1 × k kernel is…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Spending the savings

History.

  • L. Sifre (2014) studied depthwise separable convolutions in his thesis.
  • F. Chollet (2017) built Xception from them; A. Howard et al. (2017) MobileNet.
  • M. Sandler et al. (2018) introduced inverted residuals (MobileNetV2); M. Tan and Q. Le (2019) EfficientNet.

Exercise 2. A random first layer of 16 3 × 3 filters, then a second layer with a budget of 2304 weights, either standard 3 × 3 (16 output channels) or depthwise 3 × 3 plus pointwise 1 × 1 (135 output channels); global max pooling and a linear readout trained on 200 images of shapes placed anywhere. Three seeds:

second layer output channels test accuracy
standard 3 × 3 16 0.733
depthwise + pointwise 135 0.904
  • For the same weights, the separable layer was more than eight times wider and gave the readout much more useful features.
  • Caveat: these are random, untrained features; with training the gap depends on the task, but the trade of flexibility for width is the reason separable networks are efficient.
🐍 Exercise 2 (research): spending the savings
Compare a standard and a depthwise-separable second layer with the same weight budget, using random features and a linear readout.

Separable convolutions in AI, robotics and aerospace

  • Embedded perception on drones and small robots (MobileNet-SSD, EfficientDet-Lite).
  • Satellite onboard processing, where power budgets are a few watts.
  • Keyword spotting and audio events on microcontrollers with separable 1-D/2-D convolutions.

References

  1. F. Chollet (2017). “Xception: deep learning with depthwise separable convolutions.” Proc. CVPR.
  2. A. Howard et al. (2017). “MobileNets: efficient convolutional neural networks for mobile vision applications.” arXiv:1704.04861.
  3. M. Sandler, A. Howard, M. Zhu, A. Zhmoginov, L.-C. Chen (2018). “MobileNetV2: inverted residuals and linear bottlenecks.” Proc. CVPR.
  4. L. Sifre (2014). “Rigid-motion scattering for image classification.” PhD thesis, École Polytechnique.