Paper commentary
SwinIR: Image Restoration Using Swin Transformer
Swin Transformer blocks can restore degraded images better than CNNs
- 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
- 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
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}
}