Paper commentary
TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation
Transformers can serve as strong encoders for medical image segmentation
- Problem U-Net's convolutions see only local neighborhoods, so they struggle to model long-range relations across a whole organ. Transformers capture global context but lose low-level detail, and direct upsampling cannot restore it.
- Method TransUNet passes feature maps from a CNN into a Transformer encoder that models global context. A cascaded upsampler then rebuilds full resolution and receives skip-connections from the CNN features.
- Results On Synapse, TransUNet scored 77.48 average DSC, compared to 75.57 for R50-AttnUNet.
Where CNN encoders and plain Transformers fall short
Convolutional networks have become the default for medical image segmentation, and U-Net, an encoder-decoder with skip-connections, is the usual choice. Its weak point is that convolution only sees local neighborhoods, so relations across a whole organ are hard to model. That matters most when the target varies a lot between patients in texture, shape and size.
Transformers drop that locality, because self-attention lets every position interact with every other position. The open question was whether a Transformer could simply take the place of the CNN encoder in a segmentation network.
The naive attempt encodes image patches with a Transformer and upsamples the output straight to full resolution. The authors found that this gave unsatisfactory results. Their explanation is that the Transformer produces low-resolution features without precise localization, and direct upsampling can't restore that detail. So the encoder also needs low-level visual cues that a CNN can supply.
A hybrid encoder with a U-shaped decoder
The key idea is to let a CNN extract early features, let a Transformer model global context on that feature map, and let a decoder rebuild the full resolution while reusing CNN features. The CNN keeps high-resolution spatial information and the Transformer adds global context, so the two cover each other's weakness. This is the reason the authors call the design a hybrid CNN-Transformer architecture.
The authors chose a hybrid encoder for two reasons. First, the hybrid keeps the intermediate high-resolution CNN feature maps available to the decoding path. Second, they found that the hybrid encoder performs better than a pure Transformer encoder.
The decoder is a cascaded upsampler, and it receives skip-connections from the encoding path. Together the encoder and decoder form a U-shaped network, so features are combined at several resolution levels.
How one image flows through the network
The input image has size H×W with C channels, and the network predicts a label map of the same H×W size. A CNN first turns the image into a feature map, and patches are cut from that map rather than from the raw image. Each patch is then flattened and mapped by a trainable linear projection into a D-dimensional space.
Here E is the patch projection matrix, and E_pos holds one position embedding per patch. The sequence length N is set by the feature-map size divided by the patch size, so a smaller patch gives a longer sequence.
The Transformer encoder stacks layers that each apply multihead self-attention and then an MLP, with layer normalization and a residual connection around each block. In the form the authors give, \( z'_\ell = \mathrm{MSA}(\mathrm{LN}(z_{\ell-1})) + z_{\ell-1} \) and \( z_\ell = \mathrm{MLP}(\mathrm{LN}(z'_\ell)) + z'_\ell \). The default ViT encoder uses 12 Transformer layers.
The decoder reshapes the encoder sequence back to a grid of HP×WP×D. Each cascaded upsampling block applies a 2× upsampling, a 3×3 convolution and a ReLU, and with a 224 input and patch size 16, four such blocks are needed to reach full resolution. The best setting places skip-connections at the 1/2, 1/4 and 1/8 resolution scales, which are the intermediate steps before the output layer.
The authors train with SGD, a learning rate of 0.01, momentum 0.9 and weight decay 1e-4. The default batch size is 24, and ViT and ResNet-50 start from ImageNet pretraining.
Does the cascaded decoder earn its place?
With a ViT encoder, the cascaded upsampler raised average DSC from 61.50 to 67.86 on Synapse, compared to naive upsampling. This shows the decoder matters: with the same Transformer, rebuilding resolution in steps works better than one direct upsampling.
Switching the ViT encoder to the hybrid R50-ViT raises the average DSC from 67.86 to 71.29.
Synapse multi-organ results
On Synapse, TransUNet scored 77.48 average DSC with a 31.69 mm average Hausdorff distance. Its nearest CNN rival, R50-AttnUNet, scored 75.57, and R50-U-Net scored 74.68. The authors report a 1.91% gain over R50-AttnUNet, and in their table the baselines use a ResNet-50 encoder.
The skip-connections matter for the hybrid as well. Against R50-ViT-CUP, which has the same hybrid encoder but no skip-connections, TransUNet gains 6.19%. This is the paper's evidence that the CNN features passed to the decoder are doing real work.
Per organ, the gallbladder score is 87.23 for TransUNet, compared to 55.92 for R50-AttnUNet. The comparison is one dataset and one split, so the per-organ gap shows where the advantage sits on this data.
How much the skip-connections contribute
The authors varied the number of skip-connections over 0, 1 and 3 on Synapse. Adding more skip-connections generally raised average DSC, and the 1-skip setting used only the 1/4 resolution scale. The 3-skip setting, at 1/2, 1/4 and 1/8, was the best and is the TransUNet default.
The gain was larger for smaller organs such as the aorta, gallbladder, kidneys and pancreas than for the liver, spleen and stomach. The authors read this as support for adding skip-connections to recover precise low-level details.
The authors also placed a light Transformer in the 1/8-resolution skip-connection, which raised average DSC by 1.4%. They used a light Transformer there only because of GPU memory limits, and the other two skip-connections stayed unchanged.
Input resolution and patch size
The 512 input makes the Transformer sequence about 5× longer, which drives up the computation. So the authors kept 224×224 for the other comparisons.
Patch size sets sequence length, since patch size 16 gives 196 tokens and patch size 32 gives 49. With patch size 8 the sequence has 784 tokens, and average DSC rose to 77.83 from 77.48 at patch size 16. The authors chose patch size 16 as the default, following ViT.
Model size and cost
The authors compared a Base and a Large TransUNet configuration on Synapse. The Large model scored 78.52 average DSC, compared to 77.48 for Base. Because of the computation cost, the authors used the Base model for all other experiments.
Cardiac MR results on ACDC
On the ACDC dataset, TransUNet scored 89.71 average DSC, compared to 87.55 for R50-U-Net. Its average DSC was also above R50-ViT-CUP at 87.57 and R50-AttnUNet at 86.75. The ACDC split is 70 training cases, 10 validation and 20 test cases. The authors describe the gains over the pure CNN and Transformer baselines as consistent with the Synapse results.
What the example segmentations show
In the first example row, TransUNet predicts fewer false positives than the compared methods. In the second row, the pancreas boundary from R50-ViT-CUP is coarser than TransUNet's. In the third row, R50-ViT-CUP fills the inner hole of the left kidney, while TransUNet doesn't. The authors attribute this to TransUNet using both global context and low-level detail.
Limitations
The experiments use only Synapse CT and ACDC cardiac MR. The 3D volumes are predicted slice by slice and stacked into a 3D result. The 512×512 input raises cost sharply, so the authors kept 224×224 for the main comparisons. The light Transformer in the 1/8 skip-connection was used only because of GPU memory.
Paper info
- Authors
- Jieneng Chen, Yongyi Lu, Qihang Yu, Xiangde Luo, Ehsan Adeli, Yan Wang, Le Lu, Alan L. Yuille, Yuyin Zhou
- Venue
- arXiv · Preprint
- First published
- 2021-2-8
- Added
- 2026-11-11
- Updated
- 2021-2-8
- Version
- v1
- arXiv
- 2102.04306
- Category
- 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
Jieneng Chen, Yongyi Lu, Qihang Yu, Xiangde Luo, Ehsan Adeli, Yan Wang, Le Lu, Alan L. Yuille, Yuyin Zhou (2021). TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation. arXiv:2102.04306v1. https://arxiv.org/abs/2102.04306v1
BibTeX
@misc{chen2021transunet,
title = {{TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation}},
author = {Jieneng Chen and Yongyi Lu and Qihang Yu and Xiangde Luo and Ehsan Adeli and Yan Wang and Le Lu and Alan L. Yuille and Yuyin Zhou},
year = {2021},
eprint = {2102.04306},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2102.04306v1}
}