Loading...
Implement depthwise separable convolution, a key efficiency technique in MobileNets.
Standard convolution: Cin×H×W→Cout×H′×W′ Parameters: Cout×Cin×K×K
Depthwise separable breaks this into:
Efficiency gain: Cout1+K21 of standard conv!
input: (1, 3, 8, 8) # RGB image depthwise: (3, 1, 3, 3) # 3x3 per channel pointwise: (16, 3, 1, 1) # Expand to 16 channels
tensor of shape (1, 16, 6, 6)
Depthwise (no padding): (1,3,8,8) → (1,3,6,6) Each channel filtered independently
Pointwise: (1,3,6,6) → (1,16,6,6) Linear combination of channels at each spatial location
Total params: 3×9 + 16×3 = 27 + 48 = 75 Standard 3×3 conv: 16×3×9 = 432 (5.8× more!)