# Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation

Swin-Unet replaces convolutions with Transformer blocks for medical image segmentation

Hu Cao, Yueyue Wang, Joy Chen, Dongsheng Jiang, Xiaopeng Zhang, Qi Tian and 1 more · arXiv · 2021-5-12

- **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](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2105.05537v1) · [PDF ↗](https://arxiv.org/pdf/2105.05537v1)

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}
}
```

## Related papers

- [The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation](https://refivu.com/en/papers/3c8829cf-0ddd-4bc8-9b7c-cfba6d667b61-the-one-hundred-layers-tiramisu-fully-convolutional.md)
- [Swin UNETR: Swin Transformers for Semantic Segmentation of Brain Tumors in MRI Images](https://refivu.com/en/papers/44c6c3a9-434b-4cb2-aed0-e8b3167653fc-swin-unetr-swin-transformers-for-semantic-segmentation-of.md)
- [TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation](https://refivu.com/en/papers/28bfb581-8f1f-42dd-ab0d-1b3c56282f6a-transunet-transformers-make-strong-encoders-for-medical.md)
- [UNet++: A Nested U-Net Architecture for Medical Image Segmentation](https://refivu.com/en/papers/156db9ed-e303-494d-af9e-c37b8715a287-unet-a-nested-u-net-architecture-for-medical.md)
- [Domain Randomization for Transferring Deep Neural Networks from Simulation to the Real World](https://refivu.com/en/papers/3b804ec5-0ee6-4d18-8463-1dda78a4a6bf-domain-randomization-for-transferring-deep-neural-networks.md)
- [Transformers in Vision: A Survey](https://refivu.com/en/papers/5380a1d5-fae3-41ad-ab72-e650e9db12fe-transformers-in-vision-a-survey.md)

## Other paper commentary

- [The Mythos of Model Interpretability](https://refivu.com/en/papers/28c70275-bdc3-4d2e-8c3b-711d370f197b-the-mythos-of-model-interpretability.md)
- [Learning Transferable Architectures for Scalable Image Recognition](https://refivu.com/en/papers/5559067d-efe6-4393-97f1-bbf1a5119112-learning-transferable-architectures-for-scalable-image.md)
- [UCF101: A Dataset of 101 Human Actions Classes From Videos in The Wild](https://refivu.com/en/papers/a467933a-0520-4f34-b529-6224c8635422-ucf101-a-dataset-of-101-human-actions-classes.md)
- [Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression](https://refivu.com/en/papers/f29df16c-adc4-4f4f-bd28-ea43b995682d-generalized-intersection-over-union-a-metric-and-a.md)
- [FCOS: Fully Convolutional One-Stage Object Detection](https://refivu.com/en/papers/2e08cffe-e9be-4c49-9238-8afaab98cecc-fcos-fully-convolutional-one-stage-object-detection.md)
- [Dynamic Graph CNN for Learning on Point Clouds](https://refivu.com/en/papers/a7ba9236-fc2d-445b-bae5-b02e11ac4255-dynamic-graph-cnn-for-learning-on-point-clouds.md)
- [How transferable are features in deep neural networks?](https://refivu.com/en/papers/cb0b30a7-565d-41f8-bd71-41713c953bea-how-transferable-are-features-in-deep-neural-networks.md)
- [HuggingFace's Transformers: State-of-the-art Natural Language Processing](https://refivu.com/en/papers/226edb36-2edb-4a96-aca3-9909969cdf23-huggingface-s-transformers-state-of-the-art-natural.md)
- [Federated Learning: Challenges, Methods, and Future Directions](https://refivu.com/en/papers/85104455-c32d-4181-89ff-29d70a64be44-federated-learning-challenges-methods-and-future-directions.md)
- [Natural Language Processing (almost) from Scratch](https://refivu.com/en/papers/4ded66b6-2d8b-4f92-9605-511ba715f3f1-natural-language-processing-almost-from-scratch.md)
- [Recent Advances in Convolutional Neural Networks](https://refivu.com/en/papers/7bfaa2e2-6e96-45b8-b038-2820fa693e61-recent-advances-in-convolutional-neural-networks.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [u-net](https://refivu.com/en/terms/f49a93d54ad5-u-net)
- [skip connections](https://refivu.com/en/terms/8c8a0a5eff69-skip-connections)
- [Vision Transformer (ViT)](https://refivu.com/en/terms/5676f2cc1c70-vision-transformer-vit)
- [Swin Transformer](https://refivu.com/en/terms/957ac355698c-swin-transformer)
- [DSC](https://refivu.com/en/terms/c69d8ddad221-dsc)
- [bottleneck](https://refivu.com/en/terms/269ec87bcc29-bottleneck)
- [W-MSA](https://refivu.com/en/terms/31f5c71e4403-w-msa)
- [SW-MSA](https://refivu.com/en/terms/bb0e29a8b2d6-sw-msa)
- [HD](https://refivu.com/en/terms/d522e2e7c9cb-hd)
- [TransUNet](https://refivu.com/en/terms/c85c5f748b8d-transunet)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/178a13b8-5d0e-4448-a1cb-759db558ade3-swin-unet-unet-like-pure-transformer-for-medical)
