Skip to content

Depthwise separable convolution

How separate spatial filtering and channel mixing reduce a 3×3 layer from 288 to 68 weights, with the expressiveness and latency limits made explicit.

A depthwise separable convolution is a convolutional block that filters each input channel independently, then combines the filtered channels with a pointwise convolution. It reduces the number of learned weights and arithmetic operations relative to an ordinary convolution, at the cost of constraining how spatial and channel relationships interact. For a quant model processing grid-shaped market features, this can make a smaller convolutional neural network worth testing when memory or inference time is limited; it does not establish predictive usefulness.

Filter first, mix second

An ordinary convolution learns a spatial filter for every input–output channel pair and adds their contributions. A depthwise separable block splits the work:

  1. Depthwise: apply a spatial filter separately to each input channel. With depth multiplier one, four input channels produce four filtered channels. No information passes between channels at this stage.
  2. Pointwise: apply a 1×11\times1 convolution to combine those filtered values into the desired output channels. “One by one” describes the spatial footprint; the operation can use every filtered channel.
This is the construction in MobileNets §3.1. A channel is a feature dimension, such as separate measurements at each grid location, rather than another spatial position.
Four input channels pass through separate 3 by 3 filters, preserving four filtered channels; a pointwise stage mixes them into eight outputs. The weight comparison is 288 for ordinary convolution versus 36 depthwise plus 32 pointwise, totalling 68.
Four input channels pass through separate 3 by 3 filters, preserving four filtered channels; a pointwise stage mixes them into eight outputs. The weight comparison is 288 for ordinary convolution versus 36 depthwise plus 32 pointwise, totalling 68.
Original illustrative architecture: mixing occurs in the pointwise stage. Counts exclude biases and use depth multiplier one.

Where the 68 weights come from

Take a 3×33\times3 kernel, four input channels and eight output channels. Use depth multiplier one, exclude biases and normalisation parameters, and compare the same spatial output positions.

ConstructionLearned weightsCount
Ordinary convolutionNine spatial weights for each of 4 × 8 channel pairs288
Depthwise stageNine spatial weights for each of four input channels36
Pointwise stageFour input weights for each of eight output channels32
Depthwise + pointwiseBoth stages together68

For square kernel width KK, input channels CinC_{\text{in}} and output channels CoutC_{\text{out}}, the bias-free counts are

Pordinary=K2CinCout,Pseparable=K2Cin+CinCout.P_{\text{ordinary}}=K^2 C_{\text{in}}C_{\text{out}},\qquad P_{\text{separable}}=K^2 C_{\text{in}}+C_{\text{in}}C_{\text{out}}.
Our example retains 68/288=17/7268/288=17/72 of the weights, or about 76.4% fewer. Counting one multiply–accumulate per weight per output position gives the same ratio of arithmetic counts under these assumptions. The general ratio is 1/Cout+1/K21/C_{\text{out}}+1/K^2.
The ratio 288/68≈4.24288/68\approx4.24 is not a promise of 4.24 times lower latency. Memory traffic, intermediate activations and the implementation of each operation also matter. MobileNets §3.2 explicitly distinguishes arithmetic counts from efficient implementation; Xception §4.5.2 also reports speed separately from parameter count.

The saving imposes a restriction

Consider the two stages without any activation or other intervening transformation. Let Di,j,cD_{i,j,c} be the depthwise filter and Pc,oP_{c,o} the pointwise weight. Their effective ordinary-convolution kernel must satisfy

Wi,j,c,o=Di,j,cPc,o.W_{i,j,c,o}=D_{i,j,c}P_{c,o}.
For one fixed input channel, every output channel therefore sees a scalar multiple of the same spatial pattern. An unrestricted ordinary convolution can use a different pattern for each output. For example, it can read only the top-left entry for one output and only the top-middle entry for another, from that same input channel. Those two patterns are not scalar multiples, so this multiplier-one linear block cannot represent them both.
A larger depth multiplier supplies more spatial filters per input channel and changes both the count and the restriction. Nonlinearities between stages change the function again: the kernel identity above applies only to the linear composition. Activation placement is a separate design choice. MobileNets uses normalisation and ReLU around its stages, while Xception §4.7 investigates intermediate activations and uses none in its main separable operation. Neither architecture makes a separable block universally interchangeable with an ordinary layer.

Two nearby ideas to keep separate

Spatial separability factors the spatial axes, for example a 3×13\times1 operation followed by a 1×31\times3 operation. Depthwise separability separates spatial filtering from channel mixing. A depthwise 3×33\times3 filter need not itself factor into two one-dimensional filters. Xception §1.2 makes this distinction explicitly.
Grouped convolution partitions channels into groups. Depthwise filtering is the extreme grouping case, with one input channel per group; a general grouped convolution can still mix several input channels inside each group. The depthwise stage alone is only part of the separable block: the following pointwise stage restores mixing across channels. The PyTorch Conv2d reference describes these group connectivity rules.
For background on shared filters, stride and padding, Convolutional Networks for Structured Data develops the ordinary CNN construction. Its preview is public; the full lesson requires membership.

Sources

Last updated
  • deep learning
  • convolution
  • parameter efficiency
  • neural networks
← Back to the glossaryBack to top ↑