Depthwise separable convolution

Convolution · node type · Conv

Splits a convolution into a per-channel spatial filter and a 1 × 1 channel mixer, for a fraction of the cost.

Also called Depthwise conv, Separable conv, DWConv

A 3 × 3 kernel slides over the input; each output cell is the sum of the nine products under it. A depthwise convolution does exactly this once per channel, then a 1 × 1 convolution mixes the channels.

Input 7 × 7

Kernel

10-110-110-1

Output 5 × 5

-1

out[0,0] = -1×1 = -1

Figure 1. Try it: every number is computed in your browser from the formula below.

What it does

A regular convolution filters space and mixes channels in one step. A depthwise separable convolution does the two jobs separately. The depthwise step gives every input channel its own small spatial filter and keeps channels apart (an ONNX Conv with group equal to the channel count). The pointwise step is a 1 × 1 convolution that mixes channels at each pixel. The result covers the same receptive field with roughly k² times fewer multiplications for a k × k kernel, which is why mobile networks are built from it. In an exported graph it appears as two Conv nodes, usually each followed by normalization and an activation.

Formula

Z[c, y, x] = Σi Σj Wdw[c, i, j] · X[c, y + i, x + j]Y[m, y, x] = Σc Wpw[m, c] · Z[c, y, x] + bmcost ratio ≈ 1/M + 1/k2 of a full k × k convolution

Shapes and parameters

Shapes
Input [N, C, H, W]; after the depthwise step [N, C, H', W']; after the pointwise step [N, M, H', W'].
Parameters
C × kH × kW for the depthwise filters plus M × C for the pointwise mixer (plus biases if used). For C = 128, M = 128 and 3 × 3: 1,152 + 16,384 = 17,536, against 147,456 for a full 3 × 3 convolution.
Used for
MobileNet V1 and V2, many face, hand and pose detectors, and other networks sized for phones and browsers.

Figure 2. Depthwise separable convolution inside Identify houseplants, a real model in WeightSpace. The 26 outlined nodes are Depthwise separable convolution; select any node for its shapes and parameters.

Figure 3. The typed ports of Depthwise separable convolution, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only in WeightSpace today. The plant classifier runs a MobileNet built from these blocks; edits there change the classifier head after the last block, and the inspector shows the activations each block produces.