AttentionUNetForSemanticSegmentation
PretrainedModelAttentionUNetForSemanticSegmentation(config: AttentionUNetConfig)Attention U-Net for medical image segmentation (Oktay et al., MIDL 2018).
A U-Net variant that inserts a soft attention gate on every skip connection. Each gate fuses the encoder feature (the "input" branch) with the up-sampled decoder feature (the "gating signal") via
suppressing skip-feature activations outside the regions of interest highlighted by the decoder. This focuses the decoder's attention on relevant anatomy and removes the "noise" carried over from encoder layers — a consistent +1-3 Dice gain on medical-imaging benchmarks in the original paper.
Parameters
configAttentionUNetConfigattention_unet for the
standard 4-level configuration.Attributes
configAttentionUNetConfigencoderslist[_EncoderBlock]config.depth 2-D encoder stages (DoubleConv + MaxPool).bottleneck_DoubleConvdecoderslist[_DecoderBlock]config.depth decoder stages, each applying an attention gate
to the corresponding skip feature before concatenating it into
the decoder DoubleConv.headnn.Conv2dnum_classes channels.Notes
See Oktay et al., "Attention U-Net: Learning Where to Look for the Pancreas", MIDL 2018 (arXiv:1804.03999). The additive attention gate is identical to that of Bahdanau et al. (2015) generalised to feature maps:
with , . The intermediate channel count is typically half the input channels.
Examples
>>> import lucid
>>> from lucid.models.vision.attention_unet import attention_unet
>>> model = attention_unet()
>>> x = lucid.randn(1, 1, 256, 256)
>>> out = model(x)
>>> out.logits.shape # (B, num_classes, H, W)
(1, 2, 256, 256)Used by 2
Constructors
1Instance methods
1forward(x: Tensor, targets: Tensor | None = None)Run Attention U-Net.
Parameters
Returns
SemanticSegmentationOutputSemanticSegmentationOutput with logits (B, num_classes, H, W)