# SwinIR: Image Restoration Using Swin Transformer

Swin Transformer blocks can restore degraded images better than CNNs

Jingyun Liang, Jiezhang Cao, Guolei Sun, Kai Zhang, Luc Van Gool, Radu Timofte · arXiv · 2021-8-23

- **Problem** CNN restorers use the same kernel on every region and model long-range dependencies poorly. Earlier Transformer restorers cut images into fixed patches, so border pixels cannot use neighbouring pixels.
- **Method** SwinIR builds restoration from Swin Transformer blocks. It runs shallow and deep feature extraction, with plain convolutions at the entrance and exit, and predicts a residual added back to the input.
- **Results** SwinIR outperforms state-of-the-art methods by up to 0.47 dB on classical super-resolution when trained on DIV2K and Flickr2K. It also reduces the parameter count by up to 67 percent.

## Why CNN restorers and patch Transformers get stuck

Image restoration turns a degraded input into a clean image, and it covers super-resolution, denoising and JPEG artifact reduction. CNNs have become the default tool for these tasks, and most CNN work refines the architecture with residual and dense connections. The authors argue that the convolution layer itself causes two weaknesses for restoration.

The first weakness is that a convolution kernel's interaction with the image doesn't depend on the content, so the same kernel is used on every region. The second is that a convolution works locally, which makes long-range dependencies hard to model. A Transformer avoids both, because self-attention captures global interactions, but earlier restoration Transformers cut the image into fixed-size patches such as 48×48.

Each patch is processed on its own, so border pixels can't use neighbouring pixels outside the patch. Border artifacts can appear around each patch, and overlapping the patches reduces them but adds computation. Swin Transformer offers a middle path, since local attention suits large images and the shifted window scheme models long-range dependency.

## The key idea and the three-stage layout

The key idea is to put Swin Transformer blocks at the core of a restoration network, with plain convolutions at the entrance and exit of the feature path. The authors expected the convolution placed at the end of feature extraction to bring convolution's inductive bias into the Transformer part. That convolution is also meant to give a stable base for merging shallow and deep features later.

The shallow stage applies one 3×3 convolution to the low-quality input, which has size H×W×Cin, and produces a C-channel feature. The shallow feature mostly carries low frequencies, and it is passed forward for the reconstruction stage.

The deep stage runs K residual Swin Transformer blocks in sequence, and each block takes the output of the one before it. The intermediate features follow \\(F\_i = H\_{RSTB\_i}(F\_{i-1})\\), and a final 3×3 convolution gives \\(F\_{DF} = H\_{CONV}(F\_K)\\).

For super-resolution the reconstruction upsamples with a sub-pixel convolution layer, while denoising and JPEG artifact reduction use a single convolution. The network predicts a residual that is added back to the input, so the output is \\(I^{RHQ} = H\_{SwinIR}(I^{LQ}) + I^{LQ}\\).

## Inside one residual Swin Transformer block

Each RSTB runs L Swin Transformer layers on its input and then one convolution, and it adds its own input back at the end. This is written as \\(F\_{i,out} = H^{CONV}\_i(F\_{i,L}) + F\_{i,0}\\), where the layers produce \\(F\_{i,j} = H^{STL}\_{i,j}(F\_{i,j-1})\\). The authors give two reasons for the convolution, which adds spatially invariant filters and so supports translational equivariance.

The skip connection also lets features from different blocks flow into the reconstruction stage.

Inside a Swin Transformer layer, the feature is cut into non-overlapping M×M windows, and self-attention runs separately inside each window. Queries, keys and values come from shared projection matrices, so the same weights apply to every window. The attention is \\(\\mathrm{Attention}(Q,K,V) = \\mathrm{SoftMax}(QK^T/\\sqrt{d} + B)V\\), where B is a learnable relative positional encoding.

Several heads run in parallel and their outputs are concatenated, which gives the multi-head self-attention.

A two-layer MLP with GELU between the layers follows, and layer normalization sits before both the attention and the MLP. Each module has its own residual connection, so \\(X = \\mathrm{MSA}(\\mathrm{LN}(X)) + X\\) and then \\(X = \\mathrm{MLP}(\\mathrm{LN}(X)) + X\\).

## Loss functions by task

For super-resolution the authors minimise the L1 pixel loss, \\(L = \\\|I^{RHQ} - I^{HQ}\\\|\_1\\), between the output and the ground-truth image. Classical and lightweight SR use only this naive loss, so that the gains can be read as coming from the network. Real-world SR adds GAN and perceptual losses to improve visual quality.

Denoising and JPEG artifact reduction use the Charbonnier loss, \\(L = \\sqrt{\\\|I^{RHQ} - I^{HQ}\\\|^2 + \\epsilon^2}\\).

## What the ablations show about the design and the training scale

For the ablations the authors trained SwinIR on DIV2K for ×2 classical SR and tested it on Manga109. Channel number was set to 180 because PSNR kept rising with it, but the parameter count grows quadratically. The RSTB and layer numbers were both set to 6, since their gains saturate beyond that.

Table 1 compares four RSTB designs, with no residual connection, a 1×1 convolution, a 3×3 convolution and three 3×3 convolutions. The 3×3 convolution variant reaches 39.58 dB, compared to 39.42 dB with no residual connection, which is the 0.16 dB gain the authors report. The 1×1 convolution gives only 39.45 dB, which the authors attribute to its inability to capture local neighbour information the way a 3×3 kernel does.

Compared with RCAN, SwinIR's PSNR curve rises faster during training and ends higher. The gap grows as the training patch size grows. SwinIR still beats CNN models trained on the same data when only 25 percent of the images, about 200 images, are used. The authors note that this runs against earlier reports that Transformers converge slowly.

## Classical super-resolution results

Trained on DIV2K, SwinIR is best on almost all five benchmarks at ×2, ×3 and ×4. The largest gain is 0.26 dB on Manga109 at ×4. The authors attribute this to a Transformer-based design, since the CNN attention methods RCAN, HAN and NLSA all do worse.

With DIV2K+Flickr2K training the gain grows to 0.47 dB.

Visually, SwinIR restores high-frequency details and reduces blur, while most CNN methods give blurry images or wrong textures. IPT is better than the CNN methods but shows image distortions and border artifacts.

## Lightweight and real-world super-resolution

For lightweight SR the authors reduce the RSTB number to 4 and the channel number to 60. At ×2, SwinIR has 878K parameters and 195.6G Mult-Adds, compared to 1,592K parameters and 222.8G for CARN. Across the benchmarks SwinIR exceeds the compared lightweight methods by up to 0.53 dB PSNR at similar cost.

For real-world SR the authors retrained SwinIR with the degradation model of BSRGAN. There are no ground-truth HQ images in this setting, so the comparison is visual only. The authors find SwinIR's edges clearer and sharper than those of ESRGAN, RealSR, BSRGAN and Real-ESRGAN.

## Denoising and JPEG artifact reduction

SwinIR has 12.0M parameters, while DRUNet has 32.7M, so the authors read this as an efficient use of parameters. The visual results show that SwinIR keeps high-frequency details, while other methods either oversmooth or oversharpen.

For JPEG artifact reduction on Classic5 and LIVE1 at quality factors 10, 20, 30 and 40, SwinIR gains at least 0.11 dB and 0.07 dB on the two datasets.

## Limitations

The ablation studies use only ×2 classical SR tested on Manga109. Real-world SR is compared only visually, and the larger real-world model is described only on the project page. The comparisons with IPT use different training data, since IPT was trained on ImageNet. Deblurring and deraining are named as future work, so they are untested. The JPEG window size is 7 rather than 8, because the authors saw a clear drop at 8.

## Paper info

- **Authors**: Jingyun Liang, Jiezhang Cao, Guolei Sun, Kai Zhang, Luc Van Gool, Radu Timofte
- **Venue**: arXiv · Preprint
- **First published**: 2021-8-23
- **Added**: 2026-11-11
- **Updated**: 2021-8-23
- **Version**: v1
- **arXiv**: 2108.10257
- **Category**: eess.IV · cs.CV
- **Original paper terms**: [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/)
- **What we show**: Paper info and commentary

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

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

Jingyun Liang, Jiezhang Cao, Guolei Sun, Kai Zhang, Luc Van Gool, Radu Timofte (2021). SwinIR: Image Restoration Using Swin Transformer. arXiv:2108.10257v1. https://arxiv.org/abs/2108.10257v1

**BibTeX**

```
@misc{liang2021swinir,
  title = {{SwinIR: Image Restoration Using Swin Transformer}},
  author = {Jingyun Liang and Jiezhang Cao and Guolei Sun and Kai Zhang and Luc Van Gool and Radu Timofte},
  year = {2021},
  eprint = {2108.10257},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.10257v1}
}
```

## Related papers

- [Restormer: Efficient Transformer for High-Resolution Image Restoration](https://refivu.com/en/papers/df4b04d0-730a-42b5-952f-56ce280f457e-restormer-efficient-transformer-for-high-resolution-image.md)
- [Residual Dense Network for Image Super-Resolution](https://refivu.com/en/papers/01bf3f14-f3f5-49d6-9844-02a897713390-residual-dense-network-for-image-super-resolution.md)
- [Deeply-Recursive Convolutional Network for Image Super-Resolution](https://refivu.com/en/papers/93708dc4-53eb-4a15-aff5-a1add13038bd-deeply-recursive-convolutional-network-for-image-super.md)
- [Image Super-Resolution Using Very Deep Residual Channel Attention Networks](https://refivu.com/en/papers/4d16f8f5-55cc-4ee1-82f5-57e540466eec-image-super-resolution-using-very-deep-residual-channel.md)
- [MERF: Memory-Efficient Radiance Fields for Real-time View Synthesis in Unbounded Scenes](https://refivu.com/en/papers/b88df5f3-e59a-4fcd-9cfd-d031cf876738-merf-memory-efficient-radiance-fields-for-real-time.md)
- [Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising](https://refivu.com/en/papers/42b88b1a-7986-4ec5-b7e5-406b2cec7f9e-beyond-a-gaussian-denoiser-residual-learning-of-deep.md)

## Other paper commentary

- [GhostNet: More Features from Cheap Operations](https://refivu.com/en/papers/54dc4d80-177d-40dc-bde2-a797c18077da-ghostnet-more-features-from-cheap-operations.md)
- [Visual Genome: Connecting Language and Vision Using Crowdsourced Dense Image Annotations](https://refivu.com/en/papers/f53fd829-f514-4443-ae13-a5df28e84536-visual-genome-connecting-language-and-vision-using.md)
- [CSPNet: A New Backbone that can Enhance Learning Capability of CNN](https://refivu.com/en/papers/3f885aa7-65fa-4ad8-bde8-f91e2cb0eb53-cspnet-a-new-backbone-that-can-enhance-learning.md)
- [Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression](https://refivu.com/en/papers/d05dc1a3-dfd0-4eb2-bd4f-2b74602bcc42-distance-iou-loss-faster-and-better-learning-for.md)
- [YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information](https://refivu.com/en/papers/11ec3a37-5335-4563-b8f6-6949e50f3a4f-yolov9-learning-what-you-want-to-learn-using.md)
- [Context Encoders: Feature Learning by Inpainting](https://refivu.com/en/papers/7b297366-a2d7-4dfc-9233-9920c1be930e-context-encoders-feature-learning-by-inpainting.md)
- [Unsupervised Domain Adaptation by Backpropagation](https://refivu.com/en/papers/5b06ce85-04aa-40bd-a8ba-094e15a092f1-unsupervised-domain-adaptation-by-backpropagation.md)
- [Spatial Transformer Networks](https://refivu.com/en/papers/6eb29eca-41eb-4d69-ace3-032bf11562a8-spatial-transformer-networks.md)
- [Bag of Tricks for Efficient Text Classification](https://refivu.com/en/papers/48b6ecfa-f1d3-4096-8e4a-50b65a867c17-bag-of-tricks-for-efficient-text-classification.md)
- [Sparks of Artificial General Intelligence: Early experiments with GPT-4](https://refivu.com/en/papers/bf8f04ae-6d95-4b81-8fa4-4c3f7fdcc547-sparks-of-artificial-general-intelligence-early-experiments.md)
- [LINE: Large-scale Information Network Embedding](https://refivu.com/en/papers/395ad92f-93c2-44fe-8480-bbf8df48c4cf-line-large-scale-information-network-embedding.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [PSNR](https://refivu.com/en/terms/fcbb9b8276a7-psnr)
- [Convolutional Neural Network](https://refivu.com/en/terms/610f2c09337d-convolutional-neural-network)
- [image denoising](https://refivu.com/en/terms/a8fd9e9eebbc-image-denoising)
- [residual learning](https://refivu.com/en/terms/7dc1dbe26e90-residual-learning)
- [Swin Transformer](https://refivu.com/en/terms/957ac355698c-swin-transformer)
- [Urban100](https://refivu.com/en/terms/2ea226eb2e5e-urban100)
- [image super-resolution](https://refivu.com/en/terms/60ccda97aec0-image-super-resolution)
- [Classic5](https://refivu.com/en/terms/fb145cacbeb8-classic5)
- [image restoration](https://refivu.com/en/terms/b9eeb3f58f1f-image-restoration)
- [LIVE1](https://refivu.com/en/terms/295e8285536c-live1)
- [RCAN](https://refivu.com/en/terms/2659791fdb71-rcan)
- [sub-pixel convolution layer](https://refivu.com/en/terms/080ee17f48da-sub-pixel-convolution-layer)
- [SwinIR](https://refivu.com/en/terms/da992df525c4-swinir)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/16285f4a-51a3-41dc-9740-c5a9259d2b18-swinir-image-restoration-using-swin-transformer)
