Search

Search papers and lessons

Squeeze-and-Excitation Block

Level 3 · 10 min read

A squeeze-and-excitation block averages each channel of a feature map, learns one weight per channel from those averages, and rescales the channels so the network can emphasise useful ones.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Architectures
  • Probability
  • ReadReady to readNot yet

TL;DR

A squeeze-and-excitation (SE) block is a small add-on for a convolutional network that learns how much each channel of a feature map matters. It first squeezes every channel into a single average, then passes those averages through two small layers that output a weight between 0 and 1 per channel, and finally multiplies each channel by its weight. The network can then boost the channels that help the current input and damp the ones that do not.

Builds on: Global Average Pooling, Rectified Linear Unit (ReLU) · Leads to: MBConv Block

Where it's used

Image classifiers that need better accuracy for a small cost. Hu and colleagues added SE blocks to existing convolutional designs and report that the accuracy gain comes at slight additional computational cost. For SE-ResNet-50, the paper gives about 3.87 GFLOPs, a 0.26 percent relative increase over ResNet-50. The block sits after a convolution inside the existing network, so the same architecture can be upgraded without redesigning it.

Efficient mobile networks. Designs for phones use inverted bottleneck blocks such as MBConv Block, and many of them include an SE step, because it adds a few weights while letting the network focus on informative channels.

Any network built from residual blocks. The SE step is usually applied to the output of the residual branch, before it is added back to the input, so the reweighting controls how much the block changes the signal.

How it works

Take a feature map with two channels, each a 2 by 2 grid. Channel A is all 2s. Channel B is all 0.5s. We want the block to decide how strongly to pass each channel on.

  1. Squeeze: average each channel into one number. For channel A the four values average to 2. For channel B they average to 0.5. The result is a vector z = (2, 0.5), one number per channel. Check: the vector has one entry per channel, whatever the grid size.

  2. Excite: a small network turns the vector into a weight per channel. Two small layers process z. The first has a Rectified Linear Unit (ReLU) bend and compresses the vector to a shorter one. The second expands it back to two numbers, called logits. In this toy we assume the logits come out as 0 for channel A and 2 for channel B. Check: the output has one entry per channel, as the input did.

  3. Squash each logit into a weight between 0 and 1. The Sigmoid Function maps 0 to 0.5 and 2 to about 0.88. So the weights are 0.5 for channel A and 0.88 for channel B. Check: a weight of 0.5 halves a channel, and a weight near 1 leaves it almost unchanged.

  4. Scale: multiply each channel by its weight. Channel A becomes all 2 times 0.5, which is 1. Channel B becomes all 0.5 times 0.88, which is 0.44. Check: the shape of the feature map is unchanged, so the block drops into the network without other changes.

  5. Pass the rescaled map on. The next layer sees a feature map where channel A is louder than channel B, even though the original values were the other way round. Check: the rescaling depends on the input, so a different image can produce different weights.

flowchart LR
  A["Feature map, H by W by C"] --> B["Squeeze: average each channel"]
  B --> C["Vector of C numbers"]
  C --> D["Reduce with ReLU, then expand"]
  D --> E["Sigmoid gives one weight per channel"]
  E --> F["Multiply each channel by its weight"]
  A --> F
  F --> G["Rescaled feature map"]

The math

Definition: Squeeze-and-excitation block
Given a feature map U with C channels, a block computes one average per channel, passes the vector of averages through two fully connected layers with a bottleneck, and multiplies each channel of U by the resulting weight between 0 and 1.

Step 1 in symbols: the squeeze

Let uc_{c}(i, j) be the value at row i and column j of channel c, in a feature map of height H and width W. The squeeze gives one number per channel:

zc=1HW∑i=1H∑j=1Wuc(i,j)z_c = \frac{1}{H W} \sum_{i=1}^{H} \sum_{j=1}^{W} u_c(i, j)

For the toy, H = W = 2, so zA_{A} = (2+2+2+2) / 4 = 2.

Step 2 in symbols: the excitation

Write z as a column vector of length C, the kind of object a Matrix multiplies. Let r be a reduction ratio, a design choice that the paper sets to 16 by default. The excitation computes

s=σ(W2 δ(W1z))s = \sigma\big(W_2 \, \delta(W_1 z)\big)

where W1_{1} has shape (C/r) by C, W2_{2} has shape C by (C/r), δ is the Rectified Linear Unit (ReLU) activation bend and σ is the Sigmoid Function. The bottleneck of size C/r is what keeps the block cheap. In the toy, the logits 0 and 2 are the values inside σ, and the weights are sA_{A} = σ(0) = 0.5 and sB_{B} = σ(2) ≈ 0.88.

Step 3 in symbols: the scale

Each output channel is the input channel times its weight:

u~c=sc uc\tilde{u}_c = s_c \, u_c

For the toy, the output channels are 0.5 times 2, which is 1 everywhere in channel A, and 0.88 times 0.5, which is 0.44 everywhere in channel B.

−4−3−2−10123400.20.40.60.81logitweight
  • sigmoid(x)
The sigmoid turns each logit into a weight between 0 and 1. The three marked points are the logits in the toy example.

Worked examples

Example
Example 1: the squeeze on one channel

A channel is the 2 by 2 grid with rows (1, 2) and (3, 4).

  1. Add all four values: 1 + 2 + 3 + 4 = 10.
  2. Count the values: H times W = 2 times 2 = 4.
  3. Divide: 10 divided by 4 is 2.5.
  4. Interpretation: the squeeze turns the whole grid into the single number 2.5. The block now knows how strong the channel is on average but has lost where the large values are.
Example
Example 2: the full block on the toy input

Using the toy above, channel A is all 2s and channel B is all 0.5s, with logits 0 and 2.

  1. Squeeze: z = (2, 0.5).
  2. Excite: the logits are 0 for A and 2 for B.
  3. Sigmoid: sA_{A} = 0.5 and sB_{B} = 0.88.
  4. Scale channel A: 2 times 0.5 is 1.
  5. Scale channel B: 0.5 times 0.88 is 0.44.
  6. Interpretation: before the block, channel A was four times louder than channel B. After it, the gap is about 2.3 to 1 (1 divided by 0.44). The block reduced the advantage of channel A because its weight was only 0.5, and kept most of channel B.
Example
Example 3: the realistic cost of a block

A layer has C = 256 channels, and the block uses a reduction ratio r = 16.

  1. The bottleneck size is C divided by r: 256 divided by 16, which is 16.
  2. W1_{1} has shape 16 by 256, so it has 16 times 256 = 4,096 weights.
  3. W2_{2} has shape 256 by 16, so it has 256 times 16 = 4,096 weights.
  4. The block adds 4,096 plus 4,096, which is 8,192 weights. We ignore biases here.
  5. A 3 by 3 convolution from 256 channels to 256 channels has 3 times 3 times 256 times 256, which is 589,824 weights.
  6. Ratio: 8,192 divided by 589,824 is 1 divided by 72, about 0.014.
  7. Interpretation: the block adds about 1.4 percent of the weights of one such convolution, so it is a cheap addition.

Try it: the same layer with r = 8. How many weights does the block add?

Answer: the bottleneck is 256 divided by 8, which is 32. W1_{1} has 32 times 256 = 8,192 weights and W2_{2} has 256 times 32 = 8,192 weights. The total is 16,384 weights.

Common mistakes and tradeoffs

It is tempting to think that an SE block is spatial attention, which decides where in the image to look. In fact the squeeze throws away the spatial layout. The weights apply to whole channels, so the block decides which features matter for this input, not which pixels. For pixel-level focus, use a spatial mechanism instead.

It is tempting to think that the weights form a probability distribution, so they sum to 1. In fact the weights come from a sigmoid, not a Softmax, so each one is set separately. In the toy, the weights 0.5 and 0.88 do not sum to 1, and several channels can all be strongly on at once.

It is tempting to think that an SE block makes a network faster. In fact it adds a small amount of arithmetic and a global summary step, and on some hardware the global step is slow. The gain is usually in accuracy per unit of computation, not in raw speed.

When to use it: you have a convolutional network, you want a cheap accuracy gain, and the change should be a drop-in block. When not to use it: the task needs to know where things are, such as segmentation, or the latency budget is strict on hardware that handles the global step poorly. Alternatives include attention over spatial positions and simpler channel summaries.

History

Convolutional networks through the mid-2010s improved mostly by adding depth and new block designs, such as the residual and inception blocks. The idea that some channels should count for more on a given input was common in older vision methods, but in deep networks it was usually left to training.

Hu, Shen and Sun (2017) proposed the squeeze-and-excitation block as a module that existing convolutional designs could take. The authors report that SENet formed the basis of their first-place entry in the ILSVRC 2017 classification task, a claim made in the paper's abstract.

Recap

  • Squeeze: average each channel of a feature map into one number, using global average pooling.
  • Excite: a bottleneck of two small layers, with a Rectified Linear Unit (ReLU) between them, turns those numbers into logits.
  • Scale: a Sigmoid Function maps each logit to a weight between 0 and 1, and each channel is multiplied by its weight.
  • The block adds few weights, and its output depends on the input, so the network learns which channels to emphasise per image.
  • It reweights whole channels, not positions, and its weights are not a probability distribution.

Next, see how the block is used in MBConv Block, and how residual designs such as ResNet are built.

Check yourself

QuestionRecall: what does the squeeze step of a squeeze-and-excitation block compute, and what is it equivalent to?Show answer
It averages each channel of the feature map over all its rows and columns, giving one number per channel. This is the same as global average pooling applied to every channel.
QuestionCompute: a channel is the 2 by 2 grid with rows (2, 4) and (6, 8). What does the squeeze give for this channel?Show answer
The sum is 2 + 4 + 6 + 8 = 20. Dividing by 4 values gives 5.
QuestionWhy: why does the block use a sigmoid to produce the weights instead of a softmax?Show answer
A softmax forces the weights to sum to 1, so raising one channel must lower the others. A sigmoid sets each weight separately between 0 and 1, so several channels can be strongly on together. That fits the goal of choosing which channels to keep, not which one to pick.
QuestionApplied: a team adds an SE block after each convolution in a segmentation network, which must label each pixel. Their accuracy on whole-image labels improves, but the boundaries around objects get worse. What is a likely cause?Show answer
The squeeze removes spatial layout, and the weights scale whole channels, so the block cannot tell the network where the edges are. It helps decide which features matter but not where they sit. A sensible step is to keep the block only where channel information is needed, or to add a spatial mechanism for the boundaries.

Sources