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

Squeeze-and-Excitation Block

A squeeze-and-excitation (SE) block averages each channel over the whole image, passes the averages through two small fully connected layers and a sigmoid, and multiplies each channel by the resulting gate. It lets a network reweight its features using global context at little cost, and it won the 2017 ImageNet classification challenge. This page covers the squeeze, the excitation, the reduction ratio and the cost. In the exercises you build an SE block and count its parameters, then add one to a one-layer convolutional classifier and find it did not help there (0.746 against 0.773 test accuracy, with 144 more parameters): an honest null result that shows where SE's gains come from.

Level 0: Foundation

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

Turn channels up and down

Each channel of a convolutional layer detects one kind of pattern. Which patterns matter depends on the whole image: in a picture of a ship, water-texture channels matter more than fur channels. A squeeze-and-excitation block looks at the average of every channel over the whole image (the squeeze), decides from those averages how much each channel should count (the excitation), and multiplies each channel by a number between 0 and 1.

CNN building blocks
vertical edge: z = 0.84, gate 0.84
horizontal edge: z = 0.84, gate 0.84
blur: z = 0.35, gate 0.08
sharpen: z = 0.84, gate 0.84
identity: z = 0.35, gate 0.08
SE parameters for C = 64, r = 16: 580 (two small fully connected layers with biases) against 36,864 for one 3 × 3 convolution 64 → 64: 1.6%
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

SE blocks add a few percent to the cost of a network and usually improve accuracy; they appear in SENet, MobileNetV3 and EfficientNet (E8-17, E8-19, E8-20), which run on phones, drones and satellites.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The squeeze step computes…
  2. 2. Each channel is multiplied by…
  3. 3. The gates depend on…

Level 1: Beginner

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

By hand

  • Squeeze: zc = (1/HW) Σᵢⱼ uc(i, j). The 2 × 3 channel [[0, 1, 2], [3, 4, 5]] squeezes to 2.5.
  • Excitation: s = σ(W₂ ReLU(W₁z + b₁) + b₂), with W₁ of size (C/r) × C and W₂ of size C × (C/r).
  • Scale: ũc = sc·uc.
  • Parameters: 2C²/r weights plus C/r + C biases.
    • C = 256 and r = 16: 8,192 + 16 + 256 = 8,464.
    • A 3 × 3 convolution from 256 to 256 channels has 589,824 weights, so the SE block adds about 1.4%.
  • Sigmoid values: σ(0) = 0.5 and σ(2) ≈ 0.881.
📝 Quick check (Level 1)
0/3 answered
  1. 1. SE parameters (with biases) for C = 256, r = 16:
  2. 2. σ(0) =
  3. 3. The reduction ratio r controls…

Level 2: Intermediate

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

SE in code

Exercise 1.

  • The gates lay strictly between 0 and 1.
  • Each output channel equalled its input channel times its gate.
  • Changing one pixel changed the gates; flipping the image did not, because averages ignore position.
  • For C = 256 and r = 16 the block has 8,464 parameters, about 1.4% of a 3 × 3 convolution with 256 in and out channels.

Practice.

  • Put the block after the last convolution of each residual branch, before the addition (SE-ResNet).
  • The original paper uses r = 16. MobileNetV3 uses r = 4 with a hard sigmoid in place of σ.
  • Initialising the last bias so that gates start near 1 keeps the pretrained behaviour when inserting SE into an existing network.
class SE(nn.Module):
    def __init__(self, c, r=16):
        super().__init__(); self.fc1 = nn.Linear(c, c // r); self.fc2 = nn.Linear(c // r, c)
    def forward(self, u):                       # u: (N, C, H, W)
        s = torch.sigmoid(self.fc2(F.relu(self.fc1(u.mean((2, 3))))))
        return u * s[:, :, None, None]
🐍 Exercise 1: an SE block
Implement the squeeze, excitation and scale steps and count the parameters.
📝 Quick check (Level 2)
0/3 answered
  1. 1. In SE-ResNet the block goes…
  2. 2. MobileNetV3 replaces σ by…
  3. 3. Flipping the image changes the gates?

Level 3: Advanced

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

Theory

Channel attention. The SE block is a form of attention over channels. The gate vector s is a function of the whole input, so the layer’s effective filters become input-dependent: the output is Σ sc(x)·uc, a dynamic reweighting that a fixed convolution cannot express.

Why global context helps. A 3 × 3 convolution early in a network sees only a small patch. The squeeze gives every position access to an image-wide summary, so channels can be suppressed or emphasised based on what is present elsewhere. Hu et al. (2018) found gates in early layers are similar across classes and become class-specific in later layers.

Cost and bottleneck. The bottleneck C/r keeps the cost small and limits capacity; the paper found r = 16 a good trade-off. The extra multiply–adds are negligible (C²·2/r per image against HW·C²·k² for a convolution), but the global pooling is a synchronisation point that can slow inference on some hardware.

When it does not help. The squeeze reduces each channel to one number. In a shallow network with few channels the classifier already sees those averages, so the gate adds little information (exercise 2). Gains reported in the literature come from deep networks with hundreds of channels.

📝 Quick check (Level 3)
0/3 answered
  1. 1. An SE block makes the effective filters…
  2. 2. Hu et al. found later-layer gates are…
  3. 3. A hardware cost of SE is…

Level 4: Expert

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

Does the gate help a small network?

History.

  • J. Hu, L. Shen, G. Sun (2018) introduced squeeze-and-excitation networks; SENet won ILSVRC 2017 classification.
  • SE-ResNet-50 has about 10% more parameters than ResNet-50 (about 28 million against 25.6 million) and lowered top-1 error on ImageNet from 24.8% to 23.3%.
  • A. Howard et al. (2019) used SE in MobileNetV3; M. Tan and Q. Le (2019) in EfficientNet.
  • S. Woo et al. (2018) added spatial attention in CBAM (E7-11).

Exercise 2. The network is one 3 × 3 convolution with 16 filters, then ReLU, an optional SE block (r = 4, no first-layer bias), global average pooling and a linear classifier. It is trained with Adam for 300 steps on 200 noisy 12 × 12 images of four shapes (bar, column, diagonal, square), each with its own noise level. Test accuracy on 600 new images, averaged over 3 seeds:

network parameters test accuracy
conv only 228 0.773
conv + SE block 372 0.746
  • SE did not help here. It added 144 parameters (63% more) and accuracy fell slightly, by an amount comparable to seed-to-seed variation.
  • Why. With one layer, the classifier already receives the channel averages that the SE block squeezes, so the gate can only rescale information the classifier already has. SE’s reported gains come from deep networks, where gates in one layer change what later layers compute.
  • The lesson is to test a module in the setting you care about, not to assume a published gain transfers.
🐍 Exercise 2 (research): does SE help a small network?
Train a one-layer convolutional classifier with and without an SE block and compare test accuracy and parameter counts.

SE blocks in AI, robotics and aerospace

  • Mobile and embedded vision: MobileNetV3 and EfficientNet use SE in networks deployed on phones, drones and robots.
  • Remote sensing: channel attention reweights spectral bands in multispectral and hyperspectral satellite classification.
  • Medical and industrial inspection: SE variants of U-Net and ResNet are common baselines.

References

  1. J. Hu, L. Shen, G. Sun (2018). “Squeeze-and-excitation networks.” Proc. CVPR.
  2. A. Howard et al. (2019). “Searching for MobileNetV3.” Proc. ICCV.
  3. M. Tan, Q. V. Le (2019). “EfficientNet: rethinking model scaling for convolutional neural networks.” Proc. ICML.
  4. S. Woo, J. Park, J.-Y. Lee, I. S. Kweon (2018). “CBAM: convolutional block attention module.” Proc. ECCV.