# Uformer: A General U-Shaped Transformer for Image Restoration

Uformer restores degraded images with window-restricted Transformer blocks

Wang, Zhendong, Cun, Xiaodong, Bao, Jianmin, Zhou, Wengang, Liu, Jianzhuang, Li, Houqiang · arXiv · 2021-6-6

- **Problem** Convolutional restoration networks capture long-range dependencies only weakly. Global self-attention could model them, but its cost grows quadratically on high-resolution feature maps.
- **Method** Uformer builds a U-shaped encoder-decoder from LeWin blocks that attend within non-overlapping windows instead of globally. A learnable window-sized bias is added to decoder features.
- **Results** Uformer-B reaches 39.89 dB PSNR on SIDD real-noise denoising, at least 0.14 dB above the other compared denoising methods.

## Why restoration needs both local and global context

Most recent strong restoration methods are built on convolutional networks, which handle local structure well but capture long-range dependencies only weakly. Self-attention can model those long-range relations, but its cost grows quadratically with the size of the feature map, so earlier restoration work applied it only to a few low-resolution maps.

The study asks whether attention can work across several resolutions at once, so that fine detail at high resolution is also recovered.

Global attention over all tokens is impractical on high-resolution maps, and attention by itself does not exploit the neighbourhood of each degraded pixel well enough for restoration.

## How the U-shaped network turns a degraded image into a restored one

A 3×3 convolution with LeakyReLU first maps the degraded image to low-level features with C channels. Each of the K encoder stages stacks LeWin blocks and then downsamples with a 4×4 convolution of stride 2, which doubles the channel count while the spatial size shrinks. A bottleneck of LeWin blocks sits at the lowest resolution, where the window covers a larger part of the image.

The decoder mirrors the encoder: a 2×2 transposed convolution with stride 2 halves the channels and doubles the spatial size, and the result is concatenated with the matching encoder features through skip-connections before the next LeWin blocks. A final 3×3 convolution turns the decoder features into a residual R, and the restored image is I' = I + R, so the network learns a correction to its input.

## Window attention inside the LeWin block

Each LeWin block is a pair of residual sub-blocks: window-based self-attention on layer-normalised input, followed by the feed-forward module on layer-normalised output. Written out, \\(X'\_l = \\text{W-MSA}(\\text{LN}(X\_{l-1})) + X\_{l-1}\\) and \\(X\_l = \\text{LeFF}(\\text{LN}(X'\_l)) + X'\_l\\), where LN is layer normalisation.

W-MSA splits the feature map into non-overlapping M×M windows, giving \\(N = HW/M^2\\) windows, and attention is computed only among the tokens of each window. Each head works with dimension \\(d\_k = C/k\\), and the head outputs are concatenated and projected linearly. A learnable relative position bias B, read from a table of size \\((2M-1)\\times(2M-1)\\), is added to the attention logits, so that the attention is \\(\\text{SoftMax}(QK^T/\\sqrt{d\_k} + B)V\\).

Global attention costs \\(O(H^2W^2C)\\), whereas window attention costs \\(O(M^2HWC)\\), so for a fixed window size the cost scales with the number of pixels rather than their square. The window stays at 8×8 in every LeWin block, so at deeper levels, where the map is smaller, the same window covers a larger share of the image.

## Adding local context to the feed-forward path

The feed-forward network in a standard Transformer has limited ability to use local context, yet neighbouring pixels are important references in restoration. LeFF raises each token to a higher dimension with a linear layer, reshapes the tokens into a 2D map, applies a 3×3 depth-wise convolution, flattens the map back into tokens, and projects down to the input channel count.

GELU follows each linear or convolution layer.

The authors also tried a shifted-window strategy in the even LeWin blocks of each stage, which gave only slightly better results.

## The multi-scale restoration modulator

Different degradations leave different perturbation patterns, so the modulator is meant to let the decoder adjust its features per degradation. Each LeWin block in the decoder holds a learnable tensor of shape M×M×C, where M is the window size and C is the channel count, and this tensor is added as a bias shared by all windows before self-attention.

Because the bias has window size and is added rather than multiplied in, the parameter and compute increase is small.

The authors show deblurring and denoising results with and without the modulator, and read the difference as more blur and noise patterns being removed. They relate the idea to StyleGAN, which adds a multi-scale noise term to convolution features, and offer that link as a possible explanation rather than a proof.

## Training and model variants

Training uses AdamW with momentum terms of (0.9, 0.999) and a weight decay of 0.02, with random horizontal flips and rotations of 90°, 180° or 270°. The learning rate follows a cosine decay from 2e-4 down to 1e-6, the window size is 8×8 and the number of encoder and decoder stages K is 4 by default. Uformer-T uses C = 16 with encoder depths {2, 2, 2, 2}, Uformer-S uses C = 32 with the same depths, and Uformer-B uses C = 32 with depths {1, 2, 8, 8}; decoder depths mirror the encoder.

PSNR and SSIM are computed in RGB, except for deraining, where they are computed on the Y channel of YCbCr.

## Real noise removal on SIDD and DND

The margin over the other compared denoising methods is at least 0.14 dB, and the eight baselines include BM3D, RIDNet, VDN, DANet, CycleISP, MIRNet, MPRNet and NBNet.

On DND, the model trained on SIDD reaches 39.98 dB PSNR through online server testing, which is 0.09 dB above NBNet's 39.89 dB.

To check whether the gain comes only from extra compute, the authors plot PSNR against GMACs, and they report that Uformer-T performs better than most models at the lowest computation.

## Motion deblurring with GoPro-only training

Uformer is trained on GoPro only and then applied directly to HIDE, RealBlur-R and RealBlur-J, so those scores measure transfer to other data rather than fit to their training sets.

On RealBlur-R, Uformer-B reaches 36.22 dB and on RealBlur-J 29.06 dB, margins of at least 0.23 dB and 0.36 dB over the other compared methods. On HIDE, Uformer-B reaches 30.83 dB, slightly below MPRNet at 30.96 dB.

## Defocus deblurring and real deraining

The SPAD comparison uses the Y channel of YCbCr for both metrics.

## Transformer blocks against convolution and a single-scale ViT

Replacing every LeWin block with a ResBlock gives the UNet variants, sized with C = 32, 48 and 76 for UNet-T, UNet-S and UNet-B, all with encoder depths {2, 2, 2, 2}.

The single-scale ViT has a convolutional head and tail with 12 Transformer blocks of hidden dimension 256 on 16×16 patches, and it reaches 38.51 dB. The authors read the gap to Uformer as evidence that the hierarchical structure matters for restoration.

## Where locality helps

Three settings are compared: no locality, locality in W-MSA, and locality in LeFF, measured on Uformer-S for SIDD and on Uformer-B for RealBlur-R and RealBlur-J. Adding locality to the feed-forward network raises Uformer-S from 39.74 dB to 39.77 dB on SIDD, and Uformer-B from 36.15 dB and 28.99 dB to 36.22 dB and 29.06 dB on RealBlur-R and RealBlur-J.

Locality in W-MSA alone changes SIDD PSNR by -0.02 dB, from 39.74 dB to 39.72 dB.

Using both at once lowers RealBlur-R and RealBlur-J from 36.22 dB and 29.06 dB to 36.19 dB and 28.85 dB, so the authors prefer the feed-forward placement.

## Effect of the modulator across tasks

The modulator is switched off and on for Uformer-T on GoPro, and for Uformer-B on SIDD and on SPAD. On GoPro, PSNR rises from 29.11 dB to 29.57 dB, a 0.46 dB gain. For Uformer-B, PSNR rises from 39.86 dB to 39.89 dB on SIDD and from 47.43 dB to 47.84 dB on SPAD, a 0.03 dB and a 0.41 dB gain.

These three gains come from different backbones and datasets, so they are separate measurements rather than one shared effect size.

## Limitations

The evaluated tasks are denoising, motion deblurring, defocus deblurring and deraining, and image-to-image translation and image super-resolution were not tested. The SIDD gain of the modulator is 0.03 dB and was measured only on Uformer-B, and the DND score comes from online server testing of a model trained on SIDD. The authors also note that restoration techniques can be misused, for example for privacy violations in surveillance, and that they can disturb camera identification and copyright tracing.

## Paper info

- **Authors**: Wang, Zhendong, Cun, Xiaodong, Bao, Jianmin, Zhou, Wengang, Liu, Jianzhuang, Li, Houqiang
- **Venue**: arXiv · Preprint
- **First published**: 2021-6-6
- **Added**: 2026-11-12
- **Updated**: 2021-11-25
- **Version**: v2
- **arXiv**: 2106.03106
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

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

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

Wang, Zhendong, Cun, Xiaodong, Bao, Jianmin, Zhou, Wengang, Liu, Jianzhuang, Li, Houqiang (2021). Uformer: A General U-Shaped Transformer for Image Restoration. arXiv:2106.03106v2. https://arxiv.org/abs/2106.03106v2

**BibTeX**

```
@misc{zhendong2021uformer,
  title = {{Uformer: A General U-Shaped Transformer for Image Restoration}},
  author = {Wang, Zhendong and Cun, Xiaodong and Bao, Jianmin and Zhou, Wengang and Liu, Jianzhuang and Li, Houqiang},
  year = {2021},
  eprint = {2106.03106},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.03106v2}
}
```

## Other paper commentary

- [Bridging the Gap Between Anchor-based and Anchor-free Detection via Adaptive Training Sample Selection](https://refivu.com/en/papers/a286d37a-f6cf-498c-9170-fa2a9627c54e-bridging-the-gap-between-anchor-based-and-anchor.md)
- [YOLACT: Real-time Instance Segmentation](https://refivu.com/en/papers/5c58130c-e869-497b-8b85-e21d46848fe1-yolact-real-time-instance-segmentation.md)
- [SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks](https://refivu.com/en/papers/bd27ac05-aab2-4448-8e23-79659dfe759b-siamrpn-evolution-of-siamese-visual-tracking-with-very.md)
- [A Review on Deep Learning Techniques Applied to Semantic Segmentation](https://refivu.com/en/papers/8ae0e955-3ed5-48a2-b638-f9e5d7aa334e-a-review-on-deep-learning-techniques-applied-to.md)
- [Run, Don't Walk: Chasing Higher FLOPS for Faster Neural Networks](https://refivu.com/en/papers/dffa1011-36cd-44c9-b21a-c10cc00af851-run-don-t-walk-chasing-higher-flops-for.md)
- [An All-in-One Network for Dehazing and Beyond](https://refivu.com/en/papers/03c50633-ad40-4af4-b88a-e6cb99e97639-an-all-in-one-network-for-dehazing-and.md)
- [Benchmarking Neural Network Robustness to Common Corruptions and Perturbations](https://refivu.com/en/papers/68d5da5e-9028-4e0b-9bd6-89ee4c213027-benchmarking-neural-network-robustness-to-common-corruptions.md)
- [Non-negative matrix factorization with sparseness constraints](https://refivu.com/en/papers/56eb7310-b0a6-4b18-9880-4ca6ff6f54dc-non-negative-matrix-factorization-with-sparseness.md)
- [A Gentle Introduction to Conformal Prediction and Distribution-Free Uncertainty Quantification](https://refivu.com/en/papers/f99c2916-c5f5-45e3-8503-ed9342776182-a-gentle-introduction-to-conformal-prediction-and.md)
- [Neural Turing Machines](https://refivu.com/en/papers/98345e56-0459-409a-bde9-37eadc2f2d0a-neural-turing-machines.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [PSNR](https://refivu.com/en/terms/fcbb9b8276a7-psnr)
- [SSIM](https://refivu.com/en/terms/a5c530b66e8d-ssim)
- [self-attention](https://refivu.com/en/terms/426589b81077-self-attention)
- [layer normalization](https://refivu.com/en/terms/7af9eccdb60d-layer-normalization)
- [image denoising](https://refivu.com/en/terms/a8fd9e9eebbc-image-denoising)
- [ViT](https://refivu.com/en/terms/c041b72c53b8-vit)
- [UNet](https://refivu.com/en/terms/0da000173b9b-unet)
- [W-MSA](https://refivu.com/en/terms/31f5c71e4403-w-msa)
- [depth-wise convolution](https://refivu.com/en/terms/e7499edf2a0d-depth-wise-convolution)
- [SIDD](https://refivu.com/en/terms/c8853f6ae40c-sidd)
- [deraining](https://refivu.com/en/terms/50e11814b0c9-deraining)
- [DND](https://refivu.com/en/terms/ccbd893c2eb5-dnd)
- [skip-connection](https://refivu.com/en/terms/db87e1fc930a-skip-connection)
- [Uformer](https://refivu.com/en/terms/3f0593ca7087-uformer)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/f59714df-d19d-41d7-8c41-8c04e0636925-uformer-a-general-u-shaped-transformer-for-image)
