Non-Local Networks Link Distant Pixels
Non-local blocks let each pixel borrow features from far away pixels, weighted by similarity, so context crosses the whole image in one step.
Why Does This Exist?
A convolution sees neighbors only. A small ball in a wide field needs net texture from meters away, but stacking layers to reach it wastes depth.
Non-local fixes it in one block. It extends convolutional layers, generalizes spatial attention, and helps object detection on large scenes.
Think of It Like This
A group chat polling every member
You decide where to eat by polling all friends at once, weighting replies by how much you trust each person on food. One far friend who knows ramen outweighs three nearby friends who do not.
Pixels are friends, similarity is trust, and the blend is dinner. Where it stops: polling everyone each time costs attention, just as non-local costs compute.
How It Actually Works
For position with feature , output blends all positions :
measures similarity and transforms features. Embedded Gaussian uses , where and are learned projections, and normalizes. Add back with .
Worked example
Query pixel compares to three spots with dot scores . Exponentiate to , sum , weights . Values are , , . Blend is . Far spot two still gives a quarter vote, which convolution cannot do in one step.
Watch Out For
Paying quadratic cost on full resolution
Non-local on maps builds a affinity, blowing memory. Symptom: out of memory on first epoch. Fix: insert after downsampling or subsample with pooling before affinity.
The Quick Version
- Non-local output blends all positions weighted by learned similarity in one step.
- Scores give weights summing to 1.
- Fixture output keeps far context convolution misses.
- Cost is quadratic in pixels, so place after downsampling.
- It generalizes spatial attention from local gates to full-image blends.