Explain channel attention and spatial attention in CNNs. What information does each mechanism model?
Answer
Channel attention learns which feature channels are important, answering what semantic responses should be emphasized. It compresses spatial dimensions into channel descriptors, transforms them with a small gating network, and multiplies the resulting weights into the feature tensor. Spatial attention learns where informative regions occur by compressing or projecting the channel dimension and producing an mask. Modules such as SE use channel attention, while CBAM applies channel attention followed by spatial attention to refine both feature type and location.

Figure 1: Parallel tensor-shape explanation of what channel attention selects and where spatial attention focuses.
(1) Channel Gate: Global pooling summarizes each channel; an MLP or 1D convolution captures inter-channel dependence and outputs multiplicative weights.
(2) Spatial Gate: Average/max pooling or learned projection across channels produces spatial descriptors that a convolution maps to one attention mask.
(3) Residual Placement: Attention usually modulates an existing feature tensor and is often inserted inside a residual block; sigmoid gates reweight rather than replace the underlying features.

Figure 2: CBAM data flow from input feature through channel gating, spatial gating, residual refinement, and output.
Mathematical Formulation:
Where:
is the input feature map with height
, width
, and
channels.
is the channel mask; spatial average/max pooling and the shared
produce channel logits.
is the spatial mask; channel pooling outputs are concatenated by
and filtered by
.
is the sigmoid function;
broadcasts over
, while
broadcasts over
.
Leave a Reply