Medical Transformer: Gated Axial-Attention for Medical Image Segmentation

Jeya Maria Jose Valanarasu, Poojan Oza, Ilker Hacihaliloglu, Vishal M. Patel

TL;DR

The Medical Transformer (MedT) introduces a gated axial-attention mechanism and a "Local-Global" (LoGo) training strategy to bring the power of Transformers to medical image segmentation. By effectively handling the small-scale datasets typical of medical imaging, MedT outperforms traditional convolutional networks (like U-Net) and standard Transformers by better capturing long-range spatial dependencies.

What Problem Does This Paper Address?

For years, Convolutional Neural Networks (CNNs)—specifically architectures like U-Net—have been the gold standard for medical image segmentation. However, CNNs have a fundamental limitation: their "inductive bias" forces them to focus on local patterns. Because a convolutional kernel only looks at a small neighborhood of pixels at a time, the network struggles to understand long-range dependencies or global context.

Transformers, which rely on self-attention, are excellent at capturing these global relationships. The catch? They are notoriously "data-hungry." While vision transformers (ViTs) perform brilliantly when pre-trained on millions of images (like ImageNet-21k), medical datasets are often tiny (sometimes fewer than 100 images). Furthermore, standard self-attention is computationally expensive ($O(N^2)$ complexity), and the positional embeddings required for Transformers are difficult to learn accurately from limited data.

Methods

The authors propose two primary innovations to make Transformers viable for medical imaging:

1. Gated Axial-Attention

To solve the computational cost, the authors use Axial-Attention, which decomposes a 2D attention map into two 1D operations (one along the height axis and one along the width axis).

To solve the "small data" problem, they introduce Gating. In standard axial attention, positional embeddings are added to the keys, queries, and values to give the model a sense of structure. On small datasets, these embeddings are often poorly learned and can introduce noise. MedT adds four learnable "gates" ($G_Q, G_K, G_{V1}, G_{V2}$) that control how much influence these positional encodings have. If the model hasn't learned a reliable spatial prior, the gates can effectively "down-weight" that information.

2. Local-Global (LoGo) Training

The authors found that training on patches alone (common in Transformers) loses inter-patch dependencies, while training on the whole image can miss fine details. Their LoGo strategy uses two branches:

  • Global Branch: Operates on the original resolution but uses fewer transformer layers to capture high-level, long-range context.
  • Local Branch: Operates on 16 patches ($I/4 \times I/4$) of the image, passing them through a deeper stack of transformer layers to capture fine-grained features.
  • Fusion: The features from both branches are resampled, added together, and passed through a $1 \times 1$ convolution to produce the final segmentation mask.

Datasets

The model was evaluated on three distinct medical imaging tasks:

  • Brain US Dataset: Ultrasound scans of preterm neonatal brains (1,629 images).
  • GlaS Dataset: Microscopic images of gland segmentation (165 images).
  • MoNuSeg Dataset: Multi-organ nuclei segmentation from microscopic tissue (30 images for training, 14 for testing).

All images were resized to $128 \times 128$ (Brain US and GlaS) or $512 \times 512$ (MoNuSeg).

Key Insights and Ideas

  • The Gating "Aha" Moment: The most significant insight is that positional information is a double-edged sword. By making the influence of positional embeddings learnable via gates, the model becomes robust enough to train from scratch on small datasets without needing massive pre-training.
  • Context Prevents False Positives: Qualitative results show that MedT is much better than U-Net at ignoring background artifacts. Because MedT understands the global context, it can recognize that a "bleeding" area in a brain scan isn't part of the ventricle, even if it looks similar locally.
  • Efficiency through Decomposition: By using axial attention, the authors make it possible to use self-attention on high-resolution medical images that would otherwise crash a GPU's memory.

Key Results

MedT consistently outperformed both convolutional baselines and standard "fully-attention" models:

  • Quantitative: On the Brain US dataset, MedT achieved an F1 score of 88.84, compared to 85.37 for the standard U-Net and 87.92 for a standard Axial-Attention U-Net.
  • Small Data Resilience: On the GlaS dataset (only 85 training images), MedT achieved an F1 of 81.02, significantly outperforming the standard Axial-Attention baseline (76.26), proving the effectiveness of the gating mechanism.
  • Qualitative: Visualizations show that MedT produces much cleaner masks with fewer "stray" pixels in the background compared to Res-UNet or U-Net.

Limitations and Future Work

  • Marginal Gains on Ultra-Small Data: On the MoNuSeg dataset (the smallest tested), the improvement over the best CNN was very small (0.06%), suggesting there is a lower limit to how much a Transformer can help when data is extremely scarce.
  • Computational Overhead: While axial attention is more efficient than standard attention, MedT is still more complex than a simple U-Net. The paper notes that the MedT model has about 1.4M parameters—more than a modified U-Net (1.3M) but significantly fewer than a standard FCN (12.5M).
  • Future Directions: The authors suggest that exploring different ways to fuse the Local and Global branches or applying this to 3D volumetric data could be promising next steps.

Summary updated

BibTeX
@inproceedings{valanarasu2021medical,
  author = {Jeya Maria Jose Valanarasu and Poojan Oza and Ilker Hacihaliloglu and Vishal M. Patel},
  title = {{Medical Transformer: Gated Axial-Attention for Medical Image Segmentation}},
  booktitle = {International Conference on Medical Image Computing and Computer-Assisted Intervention},
  year = {2021},
  url = {https://openreview.net/forum?id=6a_H3KhBflI},
}

Loading related content...

Figure