Quant Memo
Advanced

Depthwise Separable Convolutions

Splitting an ordinary convolution into two cheaper steps — one that scans each channel separately, and one that only mixes channels — does almost the same job for a fraction of the parameters.

Prerequisites: Convolutional Neural Networks, One-Dimensional Convolutions for Price Series

An ordinary convolutional layer with many input and output channels does two jobs at once, every time it slides its kernel: it looks for a local pattern within each channel, and mixes information across all channels, simultaneously, in one dense operation. That combined job is expensive — parameter count scales with the product of input channels, output channels, and kernel size — and much of that expense is unnecessary, because "find a local shape" and "combine channels" are conceptually different tasks that don't need to be fused. Depthwise separable convolutions split them apart, removing most of the parameters without giving up much modeling power.

The analogy: proofreading, then translating — not both at once

Imagine an editor handed a report in five languages side by side, asked in one motion to both correct each paragraph's grammar and merge all five into a single summary. Doing both jointly, for every combination of "which fix affects which part of the merge," requires an enormous tangled rule set. It's far cheaper to split into two stages: five proofreaders each fix grammar in their own language in parallel, never looking at each other's paragraphs (a "depthwise" pass, one specialist per channel); then one person merges the five cleaned paragraphs, doing only the mixing (a "pointwise" pass). Two simple stages replace one expensive, entangled one.

standard: fused, dense separable: scan, then mix depthwise (per channel) pointwise (mix)
The standard layer fuses spatial scanning and channel mixing into one dense set of connections; the separable version scans each channel alone, then mixes with a much cheaper pointwise step.

The two stages, and the parameter counts

An ordinary convolution with kernel size kk, CinC_{in} input channels and CoutC_{out} output channels has:

Pstandard=kCinCoutP_{\text{standard}} = k \cdot C_{in} \cdot C_{out}

parameters — every output channel gets its own full kk-sized kernel applied across every input channel. A depthwise separable convolution replaces this with two much smaller stages:

  • Depthwise stage: one kk-sized kernel per input channel, applied only to that channel — no cross-channel mixing at all. Cost: kCink \cdot C_{in}.
  • Pointwise stage: a kernel of size 1 (just a per-position weighted combination across channels) mapping CinC_{in} channels to CoutC_{out} channels. Cost: CinCoutC_{in} \cdot C_{out}.
Pseparable=kCin+CinCoutP_{\text{separable}} = k \cdot C_{in} + C_{in} \cdot C_{out}

In words: instead of one operation costing (kernel size × in-channels × out-channels), you pay for a cheap per-channel scan plus a cheap channel-mixing step, and the two costs add instead of multiply.

Worked example 1: parameter count, a concrete layer

Take k=5k=5, Cin=32C_{in}=32, Cout=64C_{out}=64. Standard: Pstandard=5×32×64=10,240P_{\text{standard}} = 5 \times 32 \times 64 = 10{,}240. Depthwise separable: depthwise cost =5×32=160=5\times32=160, pointwise cost =32×64=2,048=32\times64=2{,}048, total =2,208=2{,}208. That's roughly a 4.6×4.6\times reduction in parameters, same input and output shape.

Worked example 2: the general reduction factor

Dividing the two formulas gives the reduction ratio directly:

PseparablePstandard=kCin+CinCoutkCinCout=1Cout+1k\frac{P_{\text{separable}}}{P_{\text{standard}}} = \frac{k \cdot C_{in} + C_{in} \cdot C_{out}}{k \cdot C_{in} \cdot C_{out}} = \frac{1}{C_{out}} + \frac{1}{k}

In words: the fraction of parameters kept is roughly 1/Cout+1/k1/C_{out} + 1/k — it shrinks as either the kernel or output-channel count grows. With k=5k=5, Cout=64C_{out}=64: 1/64+1/50.2161/64+1/5 \approx 0.216, i.e. about 21.6% kept (matching the 1/4.6\approx 1/4.6 found above). As CoutC_{out} or kk grow, this fraction approaches 1/k1/k alone.

Function explorer
-224.4
x = 1.00f(x) = 1.000

Try lowering the exponent above toward 1 — a term shrinking like 1/x1/x is exactly the shape of the 1/Cout1/C_{out} term in the savings ratio: gains are large at first as CoutC_{out} grows, then flatten out.

A depthwise separable convolution replaces one expensive operation that fuses "scan for local pattern" and "mix channels" with two cheap sequential ones — a per-channel spatial scan, then a channel-mixing 1×11\times1 step — cutting parameter count roughly to 1/Cout+1/k1/C_{out} + 1/k of the original, often a 4–9× reduction.

What this means in practice

The savings compound across a whole network, which is why architectures built almost entirely from depthwise separable blocks can match a standard convolutional network's accuracy with a fraction of the parameters and compute — valuable for deploying where inference speed or memory matters, such as a low-latency signal generator scoring many instruments per tick. The tradeoff is representational: since the depthwise stage never mixes channels, a single layer is strictly less expressive than a standard convolution of the same shape, so such architectures typically need slightly more layers or channels to recover equivalent accuracy.

Practice

  1. Compute PstandardP_{\text{standard}} and PseparableP_{\text{separable}} for k=3k=3, Cin=16C_{in}=16, Cout=16C_{out}=16.
  2. Using the ratio formula, at what CoutC_{out} does the parameter fraction kept fall below 10%, holding k=3k=3 fixed?
  3. Explain why the depthwise stage alone, with no pointwise stage afterward, would leave channels permanently unable to share information no matter how many depthwise-only layers you stacked.

The common confusion is thinking depthwise separable convolutions are simply a faster, drop-in equivalent to standard convolutions with no downside. They compute a genuinely different, more restricted function — spatial filtering and channel mixing are forced apart into separate steps rather than jointly optimized — so swapping one for the other in an existing architecture without adjusting depth or channel width can quietly reduce accuracy even though the parameter count and speed improve. The efficiency gain is a real design tradeoff, not a free lunch.

Related concepts

Practice in interviews

Further reading

  • Howard et al., MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications (2017)
  • Chollet, Xception: Deep Learning with Depthwise Separable Convolutions (2017)
ShareTwitterLinkedIn