Introduction
Convolutional Neural Networks (CNNs), exemplified by the industry-standard nnU-Net, have long dominated medical image segmentation due to their ability to capture local patterns. However, their inherent "inductive bias" of locality limits their ability to model long-range dependencies—a critical requirement for understanding complex anatomical structures in 3D volumes. While Transformers have addressed similar challenges in natural language processing through global self-attention, their direct application to 3D medical imaging often sacrifices the spatial precision that convolutions provide.
nnFormer (not-another transFormer) is a 3D transformer-based framework designed to bridge this gap. By interleaving convolutional layers with local and global self-attention mechanisms and introducing a novel "skip attention" bridge, nnFormer overcomes the local-receptive-field limitations of standard CNNs while maintaining the high-resolution spatial encoding necessary for clinical accuracy.
Methodology
The nnFormer architecture adopts a U-shaped design, similar to the classic U-Net, but integrates three fundamental structural innovations to balance spatial detail with global context.
Interleaved Architecture
Unlike standard Vision Transformers (ViT) that flatten raw pixels into 1D sequences, nnFormer utilizes a lightweight convolutional embedding to preserve low-level, high-resolution 3D features. The model then alternates between Transformer blocks and convolutional down-sampling layers. This interleaving ensures that the model benefits from both the precise spatial encoding of convolutions and the long-term dependency modeling of Transformers.
Local and Global Volume Attention
To manage computational complexity while maximizing receptive field, nnFormer employs two types of attention:
- Local Volume-based Multi-head Self-attention (LV-MSA): Applied in the encoder and decoder, this mechanism computes attention within restricted 3D windows, maintaining efficiency.
- Global Volume-based Multi-head Self-attention (GV-MSA): Reserved for the bottleneck where feature maps are at their lowest resolution, allowing the model to capture dependencies across the entire volume without a quadratic memory explosion.
Skip Attention Bridge
Traditional U-Nets rely on simple concatenation or summation for skip connections. nnFormer introduces an attention-based bridge where the decoder's features act as the "Query" and the encoder's features provide the "Key" and "Value." This allows the decoder to selectively attend to relevant high-resolution details from the encoder.
Key Insights
- Convolution as an Anchor: Successive convolutional layers with small kernels in the embedding stage outperform the large-kernel patch-wise embeddings typically used in ViTs for medical tasks.
- Strategic Bottleneck Placement: By confining global self-attention to the bottleneck, nnFormer achieves a massive receptive field efficiently.
- CNN-Transformer Complementarity: nnFormer and CNN-based models like nnU-Net tend to make different types of errors. Averaging their predictions (nnAvg) yields state-of-the-art results, suggesting that hybrid ensembles are highly effective.
- Boundary Precision: nnFormer significantly reduces the Hausdorff Distance (HD95), indicating superior performance in delineating organ boundaries compared to previous models.
Experimental Results
The model was validated on three major benchmarks:
- MSD Brain Tumor: nnFormer achieved a Dice Score (DSC) of 86.4%, significantly outperforming UNETR (71.1%) and TransBTS (69.6%).
- Synapse Multi-organ Segmentation: It surpassed the previous best transformer (LeViT-UNet-384s) by nearly 8% in DSC and improved average HD95 by over 6mm.
- ACDC Cardiac Challenge: nnFormer set a new benchmark with a DSC of 92.06%.
- Ensembling: The "nnAvg" ensemble (nnFormer + nnU-Net) provided the most robust results, particularly on the Synapse dataset where it improved HD95 by nearly 30%.
Conclusion
nnFormer demonstrates that the optimal path for volumetric medical segmentation lies in the synergy between convolution and self-attention. By interleaving these mechanisms, the framework achieves a "Goldilocks" balance of spatial precision and global context. While Transformers remain more computationally intensive than pure CNNs, the performance gains in boundary delineation and long-range dependency modeling mark a significant step forward for 3D medical imaging.
Summary updated