Apply a squeeze-and-excitation block to feature maps
Why it matters SE blocks are inside SENet, MobileNetV3 and EfficientNet and add accuracy for little compute.
Squeeze-and-excitation lets a CNN reweight its channels based on a global summary of the image.
Write se_block(x, W1, b1, W2, b2). x is (N, C, H, W). Squeeze: z = mean of x over H and W, shape (N, C). Excite: s = sigmoid(relu(z @ W1 + b1) @ W2 + b2), with W1 (C, C // r), b1 (C // r,), W2 (C // r, C), b2 (C,). Scale: y = x * s[:, :, None, None]. Return (y, s).
def se_block(x, W1, b1, W2, b2)Example
x has 2 channels where channel 0 is all 2 and channel 1 is all 0 (N = 1, 2x2), W1 = [[1], [0]], b1 = [0], W2 = [[1, -1]], b2 = [0, 0] gives s about [[0.8808, 0.1192]] and y channel 0 all about 1.7616, channel 1 all 0.
Understand the idea
A conv layer looks only at local patches, so no channel knows what the whole image looks like. SE fixes this cheaply: it averages each channel over the image to get a summary, runs a tiny network on those summaries, and outputs a volume knob between 0 and 1 for every channel. Like a sound mixer who listens to the whole song and then turns some instruments up and others down.
Tiny example: channel 0 averages 2, channel 1 averages 0. Hidden = relu(2 * 1 + 0 * 0) = 2. Gates = sigmoid([2, -2]) = [0.881, 0.119]. Channel 0 pixels become 2 * 0.881 = 1.762; channel 1 stays 0.
Rule: s = sigmoid(W2 relu(W1 mean_hw(x))), y = x * s per channel.
SENet won ImageNet 2017, and SE blocks are part of MobileNetV3 and EfficientNet.
Shapes and data flow
x (N,C,H,W) -> z (N,C) -> (N,C/r) -> s (N,C) -> y (N,C,H,W)