Foundations to Frontier
Tests
E. Deep Learning › E7 CNN Building Blocks

1×1 Convolution

A 1×1 convolution looks at one pixel at a time and mixes its channels with a learned matrix: it is a fully connected layer applied identically at every position. It changes the number of channels cheaply, which makes it the key to bottleneck blocks (ResNet-50), Inception modules and depthwise-separable convolutions, and stacked with nonlinearities it forms a small MLP at each pixel (Network in Network). This page covers the operation, its cost, bottlenecks and per-pixel MLPs. In the exercises you verify that a 1×1 convolution is a per-pixel linear layer and that a ResNet bottleneck has 8.5 times fewer weights than a plain 3×3 layer, then show that a single linear 1×1 layer cannot learn an XOR-like rule between channels (48% accuracy) while two 1×1 layers with a ReLU learn it (98–99%).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Mixing channels, pixel by pixel

A colour image has three numbers per pixel; deep inside a CNN there may be hundreds (channels). A 1×1 convolution does not look at neighbours at all. At each pixel it takes the vector of channel values and multiplies it by a learned matrix, producing a new set of channels. It can shrink 256 channels to 64 before an expensive layer, expand them again after, or, with a nonlinearity, compute a small neural network at every pixel.

CNN building blocks
parameters (no bias): standard 73,728 · grouped (g = 1) 73,728 · depthwise separable 8,768 (8.4× fewer) · multiply–adds per image: 231.2 M vs 27.5 M
Deep-learning "convolution" slides a small learned kernel over the input (no flip). Stride shrinks the output, padding preserves borders, dilation spreads the kernel to see further without more weights. Pooling summarises windows. Stacking layers grows the receptive field. Depthwise-separable and grouped convolutions cut cost by not connecting every input channel to every output channel. Transposed convolution upsamples, but uneven kernel overlap leaves checkerboard patterns. Squeeze-and-excitation rescales whole channels by gates computed from their global averages; CBAM adds a per-pixel spatial gate. (Here the gates are fixed functions of the averages so you can see their effect; in a network the excitation is learned.)
Why engineers care

1×1 convolutions are everywhere in efficient networks: ResNet bottlenecks, Inception modules, MobileNet’s pointwise layers, and the projections in transformers’ feed-forward blocks. They are often where most of a mobile network’s computation goes, so they dominate latency on embedded hardware.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A 1×1 convolution mixes…
  2. 2. It is equivalent to…
  3. 3. A common use is to…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Operation: y[:, i, j] = W·x[:, i, j] + b, with W of size C_out × C_in. Example: two channels [[0, 1], [2, 3]] and [[4, 5], [6, 7]] mixed by W = [1, 1] give [[4, 6], [8, 10]].
  • Parameters: C_in·C_out (+ C_out): 16 448 for 256 → 64 with bias.
  • Cost: C_in·C_out·H·W multiply–adds: 51.4 million for 256 → 64 on a 56 × 56 map.
  • Bottleneck: 1×1 (256 → 64), 3×3 (64 → 64), 1×1 (64 → 256): 16 384 + 36 864 + 16 384 = 69 632 weights, against 589 824 for a plain 3×3 (256 → 256), 8.5 times fewer.
  • Network in network: 1×1 conv → ReLU → 1×1 conv computes an MLP on each pixel’s channel vector.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Weights of a 1×1 conv 64 → 256 (no bias):
  2. 2. Bottleneck weights for 256 and width 64:
  3. 3. Two 1×1 layers with a ReLU form…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 20 minUndergraduate students and practising engineers.

1×1 convolutions in code

Exercise 1.

  • The 1×1 convolution matched an explicit per-pixel matrix product.
  • The ResNet bottleneck (256 → 64 → 64 → 256) had 69 632 weights, against 589 824 for a plain 3×3 layer.

Practice.

  • nn.Conv2d(C_in, C_out, kernel_size=1), or equivalently nn.Linear on channels-last tensors.
  • On GPUs a 1×1 convolution is a single large matrix multiplication, usually efficient; on mobile hardware it often dominates runtime, so channel widths matter.
  • Put normalisation and activation after each 1×1 in bottlenecks, and consider a final 1×1 without activation before a residual addition.
bottleneck = torch.nn.Sequential(torch.nn.Conv2d(256, 64, 1, bias=False), torch.nn.BatchNorm2d(64), torch.nn.ReLU(),
                                 torch.nn.Conv2d(64, 64, 3, padding=1, bias=False), torch.nn.BatchNorm2d(64), torch.nn.ReLU(),
                                 torch.nn.Conv2d(64, 256, 1, bias=False), torch.nn.BatchNorm2d(256))
🐍 Exercise 1: a per-pixel linear layer
Implement a 1×1 convolution, check it against per-pixel matrix products, and count bottleneck weights.
📝 Quick check (Level 2)
0/3 answered
  1. 1. On a GPU a 1×1 conv is computed as…
  2. 2. On mobile hardware 1×1 convs often…
  3. 3. nn.Linear on channels-last tensors equals…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Per-pixel linear map. A 1×1 convolution is the linear map I_(HW) ⊗ W on the flattened feature map: the same C_out × C_in matrix applied at all H·W positions. Its expressiveness across channels is exactly that of a linear layer.

Low-rank factorisation. The bottleneck factorises a C × C × 3 × 3 convolution through a narrower r-channel space, a low-rank approximation of the full kernel’s channel structure. If learned features are approximately low-rank across channels, little is lost; this is why bottlenecks work.

Cross-channel correlations. Lin, Chen and Yan (2014) argued that a linear filter followed by a nonlinearity is a weak feature extractor and replaced it by a micro-MLP (1×1 convolutions) at each position. Inception and Xception build on separating spatial filtering from channel mixing.

XOR across channels. A single linear 1×1 layer followed by a threshold can only separate channel vectors with a hyperplane; rules like “channels 0 and 1 have the same sign” are not linearly separable, so a nonlinearity between 1×1 layers is needed (exercise 2).

📝 Quick check (Level 3)
0/3 answered
  1. 1. A bottleneck approximates a convolution by…
  2. 2. Network in Network was proposed by…
  3. 3. The same-sign rule needs…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Linear versus nonlinear channel mixing

History.

  • M. Lin, Q. Chen and S. Yan (2014) introduced Network in Network with 1×1 convolutions.
  • C. Szegedy et al. (2015) used 1×1 reductions in Inception; K. He et al. (2016) in ResNet bottlenecks.
  • A. Howard et al. (2017) used pointwise 1×1 layers in MobileNet.

Exercise 2. Images with 4 channels of Gaussian noise; each pixel’s label is whether channels 0 and 1 have the same sign. Networks of 1×1 layers only, trained with Adam on 20 images (1280 pixels), tested on 50 new images. Two seeds:

1×1 layers pixel accuracy
one linear 1×1 convolution 0.475
1×1 (4 channels) + ReLU + 1×1 0.977
1×1 (16 channels) + ReLU + 1×1 0.992
  • A single linear 1×1 layer stayed at chance: the rule is XOR-like in channel space.
  • Two 1×1 layers with a ReLU learned it with as few as 4 hidden channels.
  • Lesson: 1×1 convolutions add nonlinear cross-channel processing only when combined with activations.
🐍 Exercise 2 (research): linear versus nonlinear channel mixing
Train 1×1-only networks with and without a hidden ReLU layer on a per-pixel XOR-like channel rule.

1×1 convolutions in AI, robotics and aerospace

  • Efficient backbones (ResNet-50, MobileNet, EfficientNet) for onboard perception rely on 1×1 layers.
  • Multispectral imagery: 1×1 layers combine spectral bands at each pixel, for example to classify land cover or detect plumes in satellite data.
  • Prediction heads: detection and segmentation heads end in 1×1 convolutions that map features to class scores per position.

References

  1. M. Lin, Q. Chen, S. Yan (2014). “Network in network.” Proc. ICLR.
  2. C. Szegedy et al. (2015). “Going deeper with convolutions.” Proc. CVPR.
  3. K. He, X. Zhang, S. Ren, J. Sun (2016). “Deep residual learning for image recognition.” Proc. CVPR.