Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Smarter bridges
U-Net’s bridges pass early, detailed features straight to the decoder. But early features see everything that looks alike: an organ and a similar-looking blood vessel produce the same edges.
- Attention U-Net puts a filter on each bridge. Deeper layers, which know roughly where the target is, decide which parts of the detailed features to let through.
- U-Net++ replaces each bridge with a small chain of layers, so the features crossing over are already partly processed before they meet the decoder.
When the target looks like its surroundings (a small organ among similar tissue, a damaged panel on a satellite among similar ones, a specific crop among weeds), gating which features reach the decoder reduces false positives.
- 1. An attention gate on a skip connection…
- 2. The gating signal comes from…
- 3. U-Net++ replaces each skip with…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Additive attention gate on a skip feature x with gating signal g:
- q = ReLU(W_x x + W_g g + b), then α = σ(ψᵀq + c) and the output is α·x;
- α is computed per pixel, so the gate is a spatial mask;
- with ψ = 0, α = 0.5 everywhere.
- U-Net++ nodes:
- X(i, j) with i the level and j the column, i + j ≤ depth; depth 4 gives 15 nodes;
- for j ≥ 1, X(i, j) concatenates X(i, 0), …, X(i, j − 1) and the upsampled X(i + 1, j − 1);
- with base 32 channels, X(0, 4) receives 4·32 + 64 = 192 channels.
- Skip links: U-Net has 4 same-level concatenations; U-Net++ of depth 4 has 1 + 2 + 3 + 4 + 1 + 2 + 3 + 1 + 2 + 1 = 20.
- Deep supervision: each top-row node X(0, 1…4) has an output head. Training averages their losses; at inference the network can be pruned to a shallower sub-network for speed.
- 1. Nodes in U-Net++ of depth 4:
- 2. Gate value with ψ = 0:
- 3. Deep supervision allows…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Gated and nested skips in code
Exercise 1.
- The gate passed half of each feature when neutral and almost all of it when the gating signal was strong.
- U-Net++ of depth 4 has 15 nodes, and its top-right node concatenates 5 inputs.
Practice.
- segmentation_models_pytorch provides
UnetPlusPlus. Attention gates are a few lines added to any U-Net decoder. - Attention gates add few parameters (two 1 × 1 convolutions and a 1-channel output per skip).
- U-Net++ is heavier: its nested nodes add many convolutions, so check memory.
- The gates’ α maps are a useful diagnostic: they show which regions the decoder relied on.
class Gate(nn.Module):
def __init__(self, cx, cg, ci):
super().__init__(); self.wx = nn.Conv2d(cx, ci, 1); self.wg = nn.Conv2d(cg, ci, 1); self.psi = nn.Conv2d(ci, 1, 1)
def forward(self, x, g): # g already upsampled to x's size
return x * torch.sigmoid(self.psi(torch.relu(self.wx(x) + self.wg(g))))- 1. segmentation_models_pytorch's nested model:
- 2. Attention gates add…
- 3. α maps are useful as…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
The semantic gap. Plain U-Net concatenates low-level encoder features with high-level decoder features. Their meanings differ, and the decoder must reconcile them in one step. U-Net++’s nested nodes process the encoder features gradually, with dense connections, so that by the time they meet the decoder they are semantically closer. The authors reported consistent gains over U-Net across several medical datasets.
Attention gates as learned spatial priors. Skip features are high-resolution but local, so they respond to anything with the right texture. The gating signal, from a coarser layer with a larger receptive field, knows where the target probably is. The additive gate learns to combine them, passing features only where both agree. In exercise 2 this was the difference between IoU 0.51, the best possible from skip features alone, and 0.83.
Caveats.
- A gate is only as good as its gating signal. If deeper layers mislocalise the target, the gate suppresses the wrong regions.
- In exercise 2 the gating signal is an idealised coarse mask, which overstates real gains.
- Both methods add complexity and computation, and in some benchmarks well-tuned plain U-Nets (nnU-Net) match them.
- 1. The semantic gap is between…
- 2. An attention gate fails if…
- 3. Well-tuned plain U-Nets…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Can a gate ignore look-alikes?
History.
- O. Oktay et al. (2018) introduced Attention U-Net at MIDL, for pancreas segmentation in CT.
- Z. Zhou, M. M. Rahman Siddiquee, N. Tajbakhsh and J. Liang (2018) introduced U-Net++ (UNet++); the journal version (2019) added pruning.
- Attention gates generalise additive (Bahdanau) attention, E11-9, to spatial maps.
Exercise 2. Each 64 × 64 image contains a target organ (an ellipse) and three distractor blobs of the same brightness. The skip feature is the intensity. The gating signal is a coarse map of where the target is: here idealised as the true mask averaged over 8 × 8 cells. An additive attention gate (4 hidden units) is trained on 20 images with logistic loss and tested on 20 new images:
| segmentation from | mean IoU with the target |
|---|---|
| skip features only (ideal threshold on intensity) | 0.507 |
| attention gate (skip + gating signal) | 0.829 |
- Skip features alone cannot separate the target from look-alikes: even the ideal threshold also selects the distractors (IoU 0.51).
- The gate learned to pass the target and suppress the distractors, using the coarse location from deeper layers. A second seed gave 0.49 against 0.85.
- The gating signal was idealised. In a real network it is learned, and the gain is smaller when deep features localise poorly.
Gated skips in AI, robotics and aerospace
- Medical imaging: small organs (pancreas, lesions) among similar tissue were the original targets.
- Remote sensing: attention U-Nets segment specific land features (solar farms, landslides) among look-alike surfaces.
- Inspection: gating helps isolate one component among similar parts in industrial or spacecraft imagery.
References
- O. Oktay et al. (2018). “Attention U-Net: learning where to look for the pancreas.” Proc. MIDL.
- Z. Zhou, M. M. Rahman Siddiquee, N. Tajbakhsh, J. Liang (2018). “UNet++: a nested U-Net architecture for medical image segmentation.” DLMIA workshop.
- Z. Zhou et al. (2019). “UNet++: redesigning skip connections to exploit multiscale features in image segmentation.” IEEE TMI 39(6).