Skip to content
All projects
CAP 5610 Machine Learning2025

What attention gates actually buy you

Standard U-Net against an attention gated one on BraTS 2021, everything else held fixed. The Dice scores come out identical. The boundary error does not.

U-NetAttention U-NetMONAIPyTorchBraTS 2021OptunaWeights and BiasesSLURM

10 mm

HD95, whole tumor

from 12 mm

5.5 mm

HD95, enhancing

from 7.5 mm

0.88

Dice, whole tumor

identical for both models

98%

Background voxels

the imbalance being fought

The question

Attention gates are widely said to help segmentation by suppressing irrelevant background activations. That is easy to accept and harder to test, because published comparisons usually differ in data, augmentation and schedule at the same time as the architecture. On BraTS 2021 the difficulty is concentrated in one place: roughly 98 percent of voxels are background, so a model can look strong on aggregate overlap while getting the boundary wrong.

Approach

One pipeline trains either architecture from the same configuration file, over the same data loading, augmentation, schedule and logging, so the architecture is the only thing that differs between runs. Four modalities stacked into one tensor, volumes resized to 128 by 128 by 144, DiceFocalLoss with inverse frequency and dynamic per batch class weighting, hyperparameters tuned with Optuna, five fold cross validation at 52 epochs per fold on two H100 GPUs, about ten hours a fold. Scored on Dice, sensitivity, Jaccard, HD95, precision and specificity rather than Dice alone. Joint project: I built the pipeline, the Attention U-Net and the visualisations, and my partner did the preprocessing, the Standard U-Net and the metrics.

Attention U-Net prediction against ground truth, fold 1, slice 77, with the four modalities above. The overlap is close for both models; the boundary is where they differ.
A preprocessed BraTS 2021 scan: FLAIR, T1, T1ce and T2 beside the ground truth mask, labelled background, non enhancing tumor, edema and enhancing tumor.

Outcome

The two models are indistinguishable on overlap and clearly separated on boundary. Dice is identical to two decimals on all three regions, 0.82 enhancing, 0.86 core, 0.88 whole tumor, and so is Jaccard. HD95 is where the attention gates show up: 7.5 mm to 5.5 mm on enhancing tumor, 9 to 7 on core, 12 to 10 on whole tumor. Sensitivity improves slightly across the board and precision on tumor core goes 0.87 to 0.89, with a small specificity cost on whole tumor, 0.9980 to 0.9975.

What it taught me

If the report had carried Dice alone, the honest conclusion would have been that attention gates do nothing here, and that conclusion would have been wrong. The gates buy boundary fidelity, which overlap is close to blind to, and boundary is the part a surgeon or a radiotherapy plan actually acts on. It is the same lesson my registration work keeps returning: pick the metric that can see the effect you are claiming, then report the ones that cannot alongside it.

More output

Standard U-Net training loss across the five folds over 52 epochs, converging to roughly 0.06 to 0.08.
Attention U-Net training loss, converging to roughly 0.07 to 0.09. Both models optimise cleanly, which is what makes the boundary difference attributable to the gates rather than to training.