1x1 and Depthwise Convolution

A full convolutional layer mixes information across space and across channels at once. Two special cases keep one kind of mixing and drop the other:

  • A convolution, or pointwise convolution, has kernel size . It mixes the channels at each pixel and never looks at neighboring pixels.
  • A depthwise convolution gives each of the channels its own filter. It filters each channel over space and never mixes channels.

For output channel at pixel , the convolution computes

It is the same dense layer applied to the channel vector at every pixel. It changes the number of channels without changing the height or width. Ignoring biases, the weight counts for input and output channels are:

  • Full convolution: .
  • convolution: .
  • Depthwise convolution, with : .

Intuition

A full convolution answers two questions at once: which patterns appear nearby, and how the channels combine. Splitting the two questions saves weights. A convolution handles only the channels. It acts like a small dense layer that looks down through the stack of feature maps at one pixel. A depthwise convolution handles only space. It runs a separate filter over each feature map. This is like applying a blur or edge filter to each color of an image on its own. Chaining the two recovers most of what a full layer does, at a fraction of the cost.

Properties

(A Dense Layer at Every Pixel) A convolution applies the same small dense layer to the channel vector at every pixel.

With one input and one output channel it scales every pixel by a learned constant and adds a learned bias. With many channels it computes, at each pixel, a weighted sum of all channels for each output channel. It never looks at neighboring pixels, so it does not enlarge the receptive field. Networks use it in three roles:

  • Matching shapes: it changes the channel count so that two tensors can be added across a residual connection.
  • Reducing cost: it shrinks the channels before an expensive layer.
  • Per-pixel outputs: at the end of a segmentation network it turns each pixel’s features into class scores.

(Bottleneck Blocks) Shrinking the channels with a layer before a layer, then restoring them, saves most of the weights.

A bottleneck residual block has three convolutions. The first is and reduces the channels, for example from to . The second is and works on the channels. The third is and restores channels so the result can be added to the block’s input. The weights are . One full layer at channels has , about times as many. The deep ResNets in Prince, such as ResNet-200, are built from bottleneck blocks.

(Depthwise Filters Each Channel Separately) A depthwise convolution divides the weight count by but removes all mixing between channels.

Each input channel is cross-correlated with its own filter, , and the results are stacked. A input filtered by three kernels without padding gives an output with weights. A full convolution with three output channels would need . No output channel sees more than one input channel. The layer therefore cannot detect a pattern that spans channels, such as a red-green edge. Mixing information across channels needs a separate layer, usually a convolution.

(A Spectrum of Channel Mixing) Grouped convolutions interpolate between a full convolution and a depthwise one.

Not Taught in Lecture

Grouped convolutions appear only in Prince’s chapter notes. Depthwise separable convolution was popularized by Xception (Chollet, 2017) and MobileNets (Howard et al., 2017).

A grouped convolution splits the input channels into groups. Each group is convolved only with its own share of the output channels. Its weight count is . Two settings of give familiar layers:

  • is a full convolution.
  • is a depthwise convolution.

AlexNet used to split some of its layers across two GPUs. A depthwise separable convolution follows a depthwise layer with a layer. It has weights, a fraction of a full layer. With and channels in and out, that is about . The factorization assumes that spatial filtering and channel mixing can be done one after the other. This is a constraint, though it costs little accuracy in practice.

Examples

(Easy) A 1x1 Convolution at One Pixel

A convolution maps input channels to output channels and uses a ReLU. Writing its weights as a matrix,

One pixel of the input has channel values .

(Medium) Depthwise, Full and Separable

A input is filtered with kernels, no padding and stride . The goal is output channels.

(Medium) Where the Bottleneck Saves

A residual block works on channels. One design uses two layers at channels. Another uses a bottleneck: from to , at channels, and back to .

See Also