Paper commentary
Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation
Swin-Unet replaces convolutions with Transformer blocks for medical image segmentation
- Problem CNN U-shaped networks struggle with long-range context. Each convolution sees only a small neighbourhood, so distant parts of an image are hard to relate.
- Method Swin-Unet keeps the U-shape and skip connections but builds it from Swin Transformer blocks. Images are cut into 4 by 4 patches, and shifted-window attention lets each stage relate tokens across the image.
- Results Swin-Unet scored 79.13 DSC on Synapse CT, compared to 77.48 for TransUnet. Its Hausdorff distance was 21.55, against 31.69 for TransUnet.
Why CNN segmenters miss global context
U-Net pairs a convolutional encoder that goes deeper with a decoder that climbs back to the input resolution. Skip connections carry encoder features across to the decoder, and this design spawned many variants such as Res-UNet, U-Net++ and UNet3+. The weak point is locality: a convolution only sees a small neighbourhood at each step, so relating distant parts of an image is hard.
Atrous convolutions, self-attention and image pyramids try to fix this, but they still have limits on long-range dependencies.
Transformers model long-range relations through attention, which is why researchers brought them into vision. ViT applied a Transformer to image patches, but it needed pre-training on a large dataset, and DeiT made training on ImageNet practical. The Swin Transformer then offered a hierarchical backbone that reached strong results on several vision tasks.
What remained open was whether a pure Transformer could serve as the full U-shape for segmentation, and that is the question this paper takes up.
Swin Transformer blocks as the building unit
The core idea is to build the whole U-shape, including the bottleneck, out of Swin Transformer blocks, so every stage attends over tokens instead of convolving. Before any block runs, the image is cut into non-overlapping 4 × 4 patches, and each patch holds 4 × 4 × 3 = 48 values. A linear embedding maps each patch to dimension C, so each patch becomes one token that the encoder can process.
Each Swin Transformer block has a LayerNorm layer, a multi-head self-attention module, residual connections and a two-layer MLP with GELU. Blocks come in pairs: the first applies window-based attention (W-MSA), and the second applies shifted-window attention (SW-MSA), which moves the window grid. Each pair runs as \( \hat{z}_l = \text{W-MSA}(\text{LN}(z_{l-1})) + z_{l-1} \) and \( z_l = \text{MLP}(\text{LN}(\hat{z}_l)) + \hat{z}_l \), followed by the same two steps with SW-MSA.
Inside each window, attention is \( \text{Attention}(Q,K,V)=\text{SoftMax}(QK^{T}/\sqrt{d}+B)V \), where Q, K and V hold the patches of one window and B is a bias matrix added before the softmax.
Encoder, bottleneck and decoder shapes
The merging layer gathers the four patches of each 2 × 2 neighbourhood, concatenates them, and applies a linear layer that brings the dimension to twice the original. The bottleneck has only two Swin blocks at unchanged size, because the authors note that a very deep Transformer is hard to converge.
The decoder mirrors the encoder, but it swaps merging for patch expanding layers that double the resolution. Encoder features at matching scales are concatenated with the decoder features, and a linear layer keeps the width equal to the up-sampled features. A final 4× patch expanding layer restores W × H, and a linear projection turns the features into per-pixel predictions.
Synapse results compared with TransUnet and U-Net
On the Synapse CT data, Swin-Unet scored 79.13 DSC and a 21.55 Hausdorff distance. The closest rival in the table, TransUnet, scored 77.48 DSC and 31.69 HD. So the overlap score is higher, and the boundary error drops from 31.69 to 21.55.
The authors ran their own U-Net and Att-UNet, and the table places Swin-Unet's DSC above the 77.77 of Att-UNet. They say the DSC gain over Att-UNet and TransUnet is small, but the HD improvement of about 4% and 10% points to better edge predictions. The evaluation uses 18 training and 12 testing samples, with averages over eight abdominal organs.
ACDC cardiac MRI results
On ACDC, Swin-Unet reached 90.00 average DSC, compared to 89.71 for TransUnet. The ACDC split is 70 training, 10 validation and 20 testing samples, and only average DSC is reported. The authors read this as evidence of good generalization to MR input, but the result is a single averaged score with no boundary metric.
Which design choices carry the gains
Skip connections were varied from 0 to 3, placed at the 1/4, 1/8 and 1/16 resolution scales. DSC rose from 72.46 with no skip connections to 79.13 with three. The authors kept three, which indicates that skip connections help a pure Transformer as well.
The patch expanding layer scored 79.13, compared to 77.63 for transposed convolution and 76.15 for bilinear interpolation. So the learned rearrangement beats both convolutional and interpolated up-sampling in this single Synapse comparison.
Testing at 384 × 384 input raised DSC from 79.13 to 81.12, with patch size kept at 4. The authors judged the extra computation too costly and kept 224 × 224 inputs. The base-scale model reached 79.25, compared to 79.13 for tiny, so the tiny model was adopted for the accuracy-speed trade-off.
Limitations
The encoder and decoder start from Swin Transformer weights pre-trained on ImageNet, which the authors call a possibly suboptimal scheme. The experiments use 2D images only, while most medical image data is 3D, so 3D segmentation is left to future work. The ablations were run on Synapse only, and ACDC was evaluated with average DSC alone.
Paper info
- Authors
- Hu Cao, Yueyue Wang, Joy Chen, Dongsheng Jiang, Xiaopeng Zhang, Qi Tian, Manning Wang
- Venue
- arXiv · Preprint
- First published
- 2021-5-12
- Added
- 2026-11-11
- Updated
- 2021-5-12
- Version
- v1
- arXiv
- 2105.05537
- Category
- eess.IV · cs.CV
- Original paper terms
- CC BY 4.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Hu Cao, Yueyue Wang, Joy Chen, Dongsheng Jiang, Xiaopeng Zhang, Qi Tian, Manning Wang (2021). Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation. arXiv:2105.05537v1. https://arxiv.org/abs/2105.05537v1
BibTeX
@misc{cao2021swin,
title = {{Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation}},
author = {Hu Cao and Yueyue Wang and Joy Chen and Dongsheng Jiang and Xiaopeng Zhang and Qi Tian and Manning Wang},
year = {2021},
eprint = {2105.05537},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2105.05537v1}
}