Depthwise and Pointwise Convolutions

medium
Unit 14 · Losses & CNNs0/3 to milestone

A depthwise convolution gives each input channel its own k × k filter and doesn't mix channels. A pointwise (1 × 1) convolution then mixes channels at each position. Together they approximate a full convolution with far fewer parameters and FLOPs (MobileNet).

For x: (N, C, H, W), stride 1 and zero padding pad:

  • depthwise_conv(x, W, b, pad=0) with W: (C, k, k) and b: (C,), returning (N, C, H + 2pad - k + 1, W + 2pad - k + 1)
  • pointwise_conv(x, W, b) with W: (F, C) and b: (F,)
  • flops_ratio(C, F, k): multiply-accumulates of depthwise + pointwise divided by those of a standard k × k convolution, per output position: Ck2+CFCFk2\frac{C k^2 + C F}{C F k^2}
#cnns#efficiency#mobile2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Depthwise and Pointwise Convolutions · TechGradify