A clothing classifier learns filters for patterns such as edges and textures, but their usefulness can change from one image to the next. A detail that helps identify a shoe may contribute little when the image shows a shirt. Channel attention gives the network a way to adjust each channel's contribution for the image in front of it. SENet won the 2017 ImageNet classification challenge using Squeeze-and-Excitation, while ECA supplies a smaller gating block.
We test whether those gates improve the small FashionMNIST classifier, keeping code, budget and initialisation paired. Three seeds give Squeeze-and-Excitation a 0.24-percentage-point loss, 27 times its standard error. Adding two seeds brings the mean within one standard error of zero. We build both blocks in NumPy and PyTorch to inspect that reversal.
Let's Build It
Both blocks do the same three things. Squeeze each channel's whole feature map down to a single number, decide a gate from those numbers, multiply the channel by its gate. They differ only in how the gate is decided, and that difference is the whole subject.

def sigmoid(z):
return 1.0 / (1.0 + np.exp(-z))
def se_numpy(x, W1, b1, W2, b2):
"""Squeeze-and-Excitation, in four lines."""
s = x.mean(axis=(2, 3)) # (B, C) squeeze
h = np.maximum(s @ W1.T + b1, 0.0) # (B, C/r) bottleneck
g = sigmoid(h @ W2.T + b2) # (B, C) gate
return x * g[:, :, None, None], g # scale
def eca_numpy(x, w):
"""Efficient Channel Attention. Same squeeze, gate from one 1-D convolution."""
s = x.mean(axis=(2, 3)) # (B, C)
k = len(w)
sp = np.pad(s, ((0, 0), (k // 2, k // 2)))
windows = np.lib.stride_tricks.sliding_window_view(sp, k, axis=1)
g = sigmoid(windows @ w) # (B, C)
return x * g[:, :, None, None], g
The PyTorch versions are the same computation with the loops hidden:
class SqueezeExcitation(nn.Module):
def __init__(self, channels, reduction=16):
super().__init__()
hidden = max(1, channels // reduction)
self.fc1 = nn.Linear(channels, hidden)
self.fc2 = nn.Linear(hidden, channels)
def forward(self, x):
g = torch.sigmoid(self.fc2(F.relu(self.fc1(x.mean(dim=(2, 3))))))
return x * g[:, :, None, None]
class EfficientChannelAttention(nn.Module):
def __init__(self, channels, k=None):
super().__init__()
self.k = k or adaptive_k(channels)
self.conv = nn.Conv1d(1, 1, self.k, padding=self.k // 2, bias=False)
def forward(self, x):
s = x.mean(dim=(2, 3))
g = torch.sigmoid(self.conv(s[:, None, :])).squeeze(1)
return x * g[:, :, None, None]
Running the NumPy functions against the modules on the same weights, at 64 channels:
SE max abs difference against torch: 2.384e-07
gate range 0.361 to 0.631, bottleneck width 4, parameters 580
ECA max abs difference against torch: 2.384e-07
gate range 0.429 to 0.568, kernel size 3, parameters 3
Float32 rounding, so the four lines above are the block rather than a picture of it. Note the last number on each line: 580 parameters against 3, for the same input and the same output shape.
What Just Happened?
The squeeze, the excitation and the scale
The squeeze is a global average pool, x.mean(axis=(2, 3)). A feature map of shape (B, C, H, W) becomes (B, C): one number per channel per image, the average response of that filter across the whole image. Everything spatial is thrown away deliberately. The block is not deciding where to look, it is deciding which filters mattered for this particular input.
The excitation turns those C numbers into C gates. Squeeze-and-Excitation does it with two dense layers and a bottleneck of width C/r, where r is the reduction ratio and the block's only knob. At C=64 and r=16 the bottleneck is 4 units wide, so all 64 channels have to negotiate their gates through four numbers. That is the point: the bottleneck forces the block to model relationships between channels rather than gate each one independently.
The scale is a broadcast multiply. g[:, :, None, None] turns (B, C) into (B, C, 1, 1), so every spatial position of a channel is multiplied by that channel's single gate. Nothing about the shape changes, which is why the block drops into an existing architecture without touching anything downstream.
ECA's argument against the bottleneck
ECA's claim is that the bottleneck is not the mechanism, it is the damage. Squeezing 64 channels through 4 units to model their dependencies destroys the direct correspondence between a channel and its own gate, and the reconstruction on the way out is lossy. Their alternative is to drop the cross-channel modelling almost entirely: slide a single 1-D convolution of width k along the channel axis, so each channel's gate depends on its own squeezed value and its k-1 nearest neighbours in the channel ordering.
The same k weights are reused at every channel, which is what makes the count collapse. There is no matrix that grows with C. At 64 channels the block holds three numbers.
The kernel size is not left as a hyperparameter. ECA sets it by a rule:
def adaptive_k(channels, gamma=2, b=1):
"""The nearest odd number to (log2(C) + b) / gamma."""
t = int(abs((math.log2(channels) + b) / gamma))
return t if t % 2 else t + 1
The reasoning is that a layer with more channels needs a wider neighbourhood to see enough of them, and that the relationship should be logarithmic rather than linear because channel counts themselves grow geometrically through a network. It gives k=3 up to 64 channels, k=5 from 128 to 1024, and k=7 at 2048.
The parameter counts diverge fast
At the widths in this post the gap is 742 parameters against 6. It does not stay that modest.

C SE r=16 SE r=8 SE r=4 ECA SE/ECA
64 580 1,096 2,128 3 193x
128 2,184 4,240 8,352 5 437x
512 33,312 66,112 131,712 5 6,662x
2048 526,464 1,050,880 2,099,712 7 75,209x
SE grows quadratically in C, because both dense layers are C by C/r. ECA grows logarithmically, because only the kernel width moves. That gap is the reason ECA is worth knowing about even in the cases where both work.
The Ablation Changes Its Mind
The blocks are the easy half. The measurement is the hard one.
The setup: a small CNN with 32 and 64 channels, 20,000 FashionMNIST images, 10 epochs, AdamW under a one-cycle schedule, identical for all three variants. Plain baseline, the same network with SE, the same network with ECA. The whole network is 65,834 parameters, SE adds 742 and ECA adds 6.
Pairing, before anything else
torch.manual_seed(seed) does not give you a paired comparison, and assuming it does is easy to miss. Modules draw their parameters from one stream in construction order. Insert an SE block after the first convolution and the stream shifts, so every convolution built after it receives different numbers. The three variants then differ by their attention block and by most of their initial weights, and the seed-to-seed noise you are trying to see past gets larger, not smaller.
The fix is to build a reference network with no attention, then copy its backbone into the other two:
def build_matched(variant, seed, widths=(32, 64), **kw):
torch.manual_seed(seed)
reference = SmallCNN("none", widths).state_dict()
torch.manual_seed(seed)
model = SmallCNN(variant, widths, **kw)
state = model.state_dict()
for key, value in state.items():
if ".attn." not in key and key in reference:
value.copy_(reference[key])
return model
Same initial convolutions, same batch normalisation statistics, same data order. One difference between the variants. Everything below depends on this, and the first version of this experiment did not have it. The listing is trimmed for the page; the version that produced the numbers also guards on matching shapes.
Three seeds, one confident answer
Run it over seeds 0, 1 and 2 and the result looks clean:
SE - baseline: -0.0025 -0.0024 -0.0022 mean -0.0024
ECA - baseline: -0.0022 -0.0001 -0.0013 mean -0.0012
Every seed negative for both blocks. Squeeze-and-Excitation costs 0.24 points of test accuracy, and the spread across seeds is so tight that the mean sits at 27 times its own standard error. Three runs agreeing in sign and magnitude is the point at which most ablations stop, write it up, and move on. It is a defensible place to stop, and here it is wrong.
Five seeds, none

Seeds 3 and 4 come back positive for both blocks:
| comparison | seed 0 | seed 1 | seed 2 | seed 3 | seed 4 | mean | standard error |
|---|---|---|---|---|---|---|---|
| SE − baseline | −0.0025 | −0.0024 | −0.0022 | +0.0012 | +0.0014 | −0.0009 | 0.0009 |
| ECA − baseline | −0.0022 | −0.0001 | −0.0013 | +0.0006 | +0.0002 | −0.0006 | 0.0005 |
| ECA − SE | +0.0003 | +0.0023 | +0.0009 | −0.0006 | −0.0012 | +0.0003 |
Both means are now inside one standard error of zero, and the signs no longer agree. The honest reading is that at this scale and budget, channel attention does nothing measurable in either direction, and the two blocks cannot be told apart from each other either.

Nothing changed between those two readings except the stopping point. Not the code, not the budget, not the initialisation, not the data order. The three-seed answer was not a bug and it was not bad luck in any diagnosable sense: it was a five-sample distribution read after three samples, and the first three happened to agree.
The defence is not "use more seeds", which is unaffordable advice at any interesting scale. It is to know the size of the effect you are hunting relative to the noise before deciding how many runs buy you an answer. Here the baseline alone spans 0.0042 across the five seeds, with a standard deviation of 0.0016, while the effect under test is 0.0009. When the thing you are measuring is smaller than the thing you are measuring it against, three runs cannot resolve it, and their agreement is not evidence that they can.
Going Deeper
Neither knob buys it back
The reduction ratio and the kernel size are the only knobs either block has, so the obvious question after a null result is whether the defaults were simply wrong for a network this small. Sweeping both says they were not.

Every configuration sits under the plain baseline, and the two families do not even move in the same direction. SE is at its worst at the recommended r=16, and better at both r=4 and r=32, which is not a shape any tuning story predicts. ECA is worst at k=5 and best at k=9, the widest kernel tried, while its adaptive rule picks k=3 at these widths. Three seeds per swept point and five for the two defaults, r=16 and k=3, which come from the main ablation. The ordering inside each family is noise rather than a tuning result.
The vertical axis is the part to keep. The whole sweep spans about 0.0011 of accuracy while the parameters added range from six to a few thousand, and all of it happens below the line.
The gate starts at half
There is a specific, mechanical reason to expect SE to hurt a freshly initialised network, and it has nothing to do with channel attention as an idea. The gate is a sigmoid, and a sigmoid of roughly zero is roughly one half. A newly built SE block therefore multiplies every activation passing through it by about 0.5 before it has learned anything at all.
Biasing the final layer so the gate starts near 1 makes the block close to the identity at initialisation. Doing that recovers the whole deficit:
SE, default gate 0.9038 -0.0024 against baseline, all three seeds negative
SE, gate near 1 0.9062 +0.0000 against baseline
plain baseline 0.9061
The improvement over default SE is +0.0016, +0.0027 and +0.0029, positive on every seed. On this evidence the cost is not the block's idea, it is one line of initialisation, and the fix is free.
That result is on three seeds. Everything above says what three seeds are worth, so treat it as the most promising lead in this post rather than as a finding, and re-run it at five before quoting it anywhere. The standard has to apply to the results that flatter the post as well.
Two gates, two behaviours
If the block is not buying accuracy, it is worth asking what it learned to do instead. Averaging each block's gate over the test set and grouping by class:

The two blocks did not learn the same kind of thing at all. SE's gates vary by 0.1238 across channels and by 0.0007 across classes. That second number is the one that matters: to three decimal places, SE hands every input the same gates. It has not learned attention. It has learned a fixed per-channel rescaling, which is something the network already had in its batch normalisation layers, with one channel pinned near zero and the rest saturated near one.
ECA is the reverse, 0.0173 across channels against 0.0739 across classes. Its gates depend on the input, by roughly a hundred times more than SE's do. It is doing the thing the method is named after, and it still does not show up in the accuracy.
Two blocks, opposite behaviours, the same null result. SE collapsed into a static mask and ECA attended, and neither mattered here.
Wider channels do not rescue it
Both blocks reweight channels, so their scope grows with the channel count, and a negative result at 32 and 64 channels says little about a method designed for backbones an order of magnitude wider. The obvious check is to widen the network and look again. At 64 and 128 channels, on its own smaller budget so the arm is internally comparable:

baseline 0.8914 SE 0.8909 (-0.0005) ECA 0.8905 (-0.0009)
The signs disagree across seeds for both blocks, exactly as in the main arm. Nothing appeared here either. Three seeds again, so by this post's own standard that is a statement about the absence of an obvious effect and not a measurement of its size.
Scope of the result
It does not say Squeeze-and-Excitation and ECA do not work. The papers report gains on ImageNet-scale networks with hundreds of channels per layer, trained for a hundred epochs, and nothing measured here contradicts that. Those published results are also entangled with training recipes in a way Bello and colleagues documented carefully in 2021. Much of the improvement attributed to architecture in the years since ResNet turned out to come from the training and scaling strategies that shipped alongside it.
What this post does say is narrower and more useful to the reader about to paste an SE block into a small model. At 66,000 parameters and 64 channels the block buys nothing, the default initialisation costs something real until you fix it, and the ablation you would run to check either of those needs more seeds than it feels like it needs.
Where This Comes From
Squeeze-and-Excitation was introduced by Jie Hu, Li Shen and Gang Sun in "Squeeze-and-Excitation Networks", published at CVPR in 2018 after the SENet entry won the ILSVRC 2017 classification task. Their framing is that convolutions mix channel and spatial information together, and that the channel relationships are worth modelling explicitly and separately. The squeeze is described as giving each layer a global receptive field cheaply, which a stack of small convolutions otherwise takes many layers to build.
The reduction ratio is presented in that paper as a capacity and cost trade-off rather than a tuned hyperparameter, with r=16 offered as a reasonable default across architectures. The block was designed to be architecture-agnostic, which is why it appears bolted onto ResNets, Inception variants and MobileNets alike.
ECA came from Qilong Wang and colleagues in "ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks", at CVPR in 2020. Its contribution is an empirical argument that the dimensionality reduction in SE is harmful rather than helpful, and that avoiding it while keeping the channel interaction local gives comparable accuracy at a small fraction of the cost. The adaptive kernel rule is their answer to the objection that a local method needs a locality parameter.
Woo and colleagues extended the idea along the other axis with CBAM in 2018, adding a spatial attention map after the channel one, which is the natural counterpart to everything here. The channel gate answers which filters mattered; the spatial map answers where in the image they mattered. The two compose, and CBAM applies them in that order.

Read across that timeline and the direction is consistent. SE establishes that a per-channel gate is worth having and pays thousands of parameters for it. ECA keeps the gate, removes almost all of the parameters, and reports no loss, which is a strong hint that the parameters were never where the gain lived. Bello then asks the same question of architecture in general. The measurements in this post sit at the end of that line: at a scale where the recipe is held fixed and the network is small, what remains of the gate is not measurable.
The paper to read alongside all of them is Irwan Bello and colleagues' "Revisiting ResNets: Improved Training and Scaling Strategies" from 2021. It is not about attention. It rebuilds a ResNet with a modern training and scaling recipe and shows how much of the improvement credited to architecture in the intervening years came from the recipe instead. That is the right frame for reading any reported gain of a fraction of a point, including the ones here.
Further reading
For a constructed attention example, transformer without training tests what hand-set weights can compute.
Squeeze-and-Excitation Networks, Hu, Shen and Sun, CVPR 2018. Sections 3 and 6 for the block and the reduction-ratio ablation.
ECA-Net, Wang et al., CVPR 2020. Section 3 for the argument against dimensionality reduction.
CBAM: Convolutional Block Attention Module, Woo et al., ECCV 2018, for the spatial counterpart.
Revisiting ResNets, Bello et al., NeurIPS 2021, on training-recipe confounds in architecture comparisons.
Interactive Tools
- CNN Layer Visualizer: what individual channels respond to, which is the thing the squeeze averages over.
- Convolution Visualizer: the operation both blocks attach to.
- Attention Visualizer: attention over positions, for contrast with attention over channels.
Related Posts
- Convolutional Neural Networks from Scratch: Conv2d in NumPy: the backbone both blocks are inserted into.
- Batch Normalisation from Scratch: Why It Works and When It Doesn't: the other per-channel rescaling in the same network, and a useful contrast in what a learned scale buys.
- Vision Transformers from Scratch in PyTorch: attention over positions rather than channels, at a scale where it does pay.
- Multi-Task Learning in PyTorch: When Gradients Conflict: another case where the honest measurement is harder than the method.




