Spatial Attention Masks Where to Look
Spatial attention scores every pixel location for usefulness on this image, then turns up the telling spots and mutes the clutter.
Why Does This Exist?
Convolutions share weights everywhere, so a dog ear and a blank wall get equal compute. On cluttered photos the classifier drowns in background votes.
Spatial gates fix that per image. They sit after convolutional layers, complement channel attention which scores what, and lift object detection where location decides.
Think of It Like This
A stage spotlight operator
You watch a dark stage with two actors and empty curtains. You push the spotlight to full on the speaking actor and dim it on the curtains for this scene only.
Maps are the stage, the pooled conv is your eye, and gates are the dimmer. Where it stops: a misaimed spot hides the real action, just as a wrong mask mutes the target.
How It Actually Works
Take feature maps with shape , where counts channels, height, and width. Pool across channels two ways at each location : average and max . Stack them to , run one convolution , then sigmoid :
is with values in . Rescale , where multiplies every channel at by the same gate .
Worked example
Two channels on a map. Channel 0 is and channel 1 is . Average pooling gives since and so on. Max pooling gives .
Say the conv (padded to here) outputs logits . Sigmoid gives because and . Top-left keeps while top-right drops to . The target corner counts eleven times the clutter cell.
Watch Out For
A 7 by 7 gate memorizing training clutter
A large kernel with little data learns dataset corners instead of objects. Symptom: higher train accuracy with worse crops on new scenes. Fix: keep the kernel at with strong image augmentation and check location shift by testing on shifted crops.
The Quick Version
- Spatial attention pools across channels to avg and max maps, then conv plus sigmoid makes one gate per location.
- Fixture gates 0.77 on target and 0.31 on clutter give an eleven to one emphasis after rescaling.
- It scores where, while channel attention scores what, so the pair covers both.
- Cost is one small convolution per block, far below self-attention.
- Wrong masks mute targets, so test on shifted crops before trusting gains.