Paper commentary
SwinIR: Image Restoration Using Swin Transformer
Swin Transformer blocks can restore degraded images better than convolutional networks
- Problem Convolutional restoration networks use the same kernel for every image and model long-range context poorly. Transformers cut images into patches, which leaves seams at patch borders.
- Method SwinIR is a restoration network built on Swin Transformer blocks with shifted windows. Each block adds a convolution and a residual connection, and it predicts a residual on the low-quality input.
- Results SwinIR outperforms state-of-the-art methods by 0.14 to 0.45 dB across restoration tasks. Its total parameter count is reduced by up to 67%.
Why convolution and patch-based Transformers fall short
Image restoration covers super-resolution, denoising and JPEG artifact reduction, and each task asks for a clean, high-quality image recovered from a degraded observation. Convolutional networks have become the default for these tasks, and most of their improvements come from elaborate block designs such as residual and dense connections.
The authors point to two weaknesses that come from the convolution layer itself. The kernel applies the same weights whatever the image content, so it may be a poor fit for some regions, and its local receptive field makes long-range dependencies hard to model.
Transformers capture global interactions with self-attention, but Transformer restoration models usually cut the input into fixed-size patches and process each patch on its own. Pixels near a patch border then lack neighbouring context, and seams can appear at patch edges. Overlapping patches reduce the seams, but they add computation.
The Swin Transformer combines local attention, which handles large images as a CNN does, with shifted windows, which connect distant regions across layers. SwinIR is built on that design.
From low-quality input to restored output
This paper proposes SwinIR with three modules: shallow feature extraction, deep feature extraction and high-quality image reconstruction. The first two are shared across tasks, and the reconstruction module differs by task.
The closing convolution brings a convolutional inductive bias into the Transformer stage, and it gives the later fusion with shallow features a stable starting point.
For super-resolution the reconstruction uses a sub-pixel convolution layer to upsample. Denoising and JPEG artifact reduction need no upsampling and use a single convolution. The network predicts a residual, so the output is \( I^{R}_{HQ} = H_{SwinIR}(I_{LQ}) + I_{LQ} \).
Inside a residual Swin Transformer block
Within the i-th RSTB, L Swin Transformer layers run in sequence, \( F_{i,j} = H_{STL_{i,j}}(F_{i,j-1}) \). A convolution then acts on the output of the last layer, and the block adds its input back, \( F_{i,out} = H_{CONV_i}(F_{i,L}) + F_{i,0} \). The authors give two reasons for the convolution. A Transformer can be seen as a form of spatially varying convolution, and adding spatially invariant filters restores translational equivariance.
The residual path also carries the features of each block forward to reconstruction, so the aggregation sees several feature levels.
In a Swin Transformer layer, an input of size H×W×C is split into non-overlapping M×M windows, and self-attention runs separately inside each window. The window tokens are reshaped to a count of HW/M² windows, each holding M² tokens of C channels. For one window X, the queries, keys and values are \( Q = XP_Q \), \( K = XP_K \) and \( V = XP_V \), where the projection matrices are shared across windows.
Attention in each window is \( \mathrm{Attention}(Q,K,V) = \mathrm{SoftMax}(QK^{T}/\sqrt{d} + B)V \), where B is a learnable relative positional encoding. Several such heads run in parallel and their outputs are concatenated, which is the multi-head self-attention used here.
After attention, a two-layer MLP with GELU between the layers transforms the features. LayerNorm comes before both the attention and the MLP, and each module has its own residual connection, \( X = \mathrm{MSA}(\mathrm{LN}(X)) + X \) followed by \( X = \mathrm{MLP}(\mathrm{LN}(X)) + X \).
With a fixed partition, windows never exchange information. Regular and shifted partitions therefore alternate between layers, and the shifted partition moves the feature map by half the window size, rounded down, before splitting it, which lets neighbouring windows interact.
Loss functions for each task
For classical and lightweight super-resolution, the network minimises the L1 pixel loss \( L = \|I^{R}_{HQ} - I_{HQ}\|_1 \), where \( I^{R}_{HQ} \) is produced from \( I_{LQ} \) and \( I_{HQ} \) is the ground-truth high-quality image. The authors use this plain loss so that the architecture is the only change from earlier work.
Real-world super-resolution combines a pixel loss, a GAN loss and a perceptual loss to improve visual quality.
Each task uses its own reconstruction module and loss, so a trained model is specific to the task it was trained for. Training and evaluation details are placed in the supplementary material rather than the main text.
What the convolution and residual path contribute
The RSTB ablation trains SwinIR on DIV2K and tests it on Manga109 at ×2. Four variants are compared: no residual connection, a 1×1 convolution, a 3×3 convolution, and three stacked 3×3 convolutions whose intermediate channel count is one quarter of the network width.
PSNR is 39.42 with no residual connection, 39.45 with the 1×1 convolution, 39.58 with the 3×3 convolution and 39.56 with three 3×3 convolutions. Removing the residual connection costs 0.16 dB relative to the 3×3 variant, so the residual path matters in this setting.
Three 3×3 layers reduce the parameter count, but PSNR falls slightly below the single 3×3 layer, so the authors keep one 3×3 convolution.
The same ablation sweeps channel number, RSTB number and layer number within an RSTB, on the same Manga109 ×2 setting. PSNR increases with each, and the authors select 180 channels, 6 RSTBs and 6 layers per RSTB, because gains saturate and the parameter count grows quadratically with channels.
Training data use and convergence against RCAN
SwinIR is compared with RCAN, a representative CNN model, across training patch sizes from 32 to 80. SwinIR scores higher at every patch size, and its advantage grows as the patch size increases.
Extra Flickr2K images are added once the training subset exceeds 100% of the 800 DIV2K images. SwinIR improves as more images are used, and it still beats RCAN when trained on only 25%, which is 200 images.
The training curves compare PSNR on Manga109 at ×2 against training iterations. SwinIR climbs faster and ends higher than RCAN, which the authors set against earlier reports that Transformer models converge slowly. These curves cover only this one dataset and scale, so the convergence claim rests on that single comparison.
Classical super-resolution results
When trained on DIV2K, SwinIR of middle size is compared with RCAN, SAN, IGNN, HAN, NLSA, DBPN, IPT and RRDB across Set5, Set14, BSD100, Urban100 and Manga109.
The authors report that SwinIR tops almost every benchmark at every scale among the DIV2K-trained methods. The largest margin in this comparison is 0.26 dB on Manga109 at ×4.
Training on DIV2K and Flickr2K together raises SwinIR further, by up to 0.47 dB.
The SwinIR+ entries use the self-ensemble strategy at test time. On Set5 ×4 with DIV2K+Flickr2K training, SwinIR+ scores 32.93 against 32.92 for SwinIR, and the two SSIM values are 0.9043 and 0.9044, so the self-ensemble gain is small on that benchmark.
Visually, the authors describe SwinIR as restoring sharper high-frequency edges, while CNN methods blur or invent textures and IPT shows distortions and border artifacts.
Lightweight super-resolution at a similar cost
The small SwinIR uses 4 RSTBs and 60 channels. It is compared with CARN, FALSR-A, IMDN, LAPAR-A and LatticeNet, and the comparison reports PSNR, SSIM, parameter count and multiply-accumulate operations on a 1280×720 image.
At ×2, SwinIR has 878K parameters and 195.6G multiply-accumulate operations. It scores 33.86 on Set14, 32.76 on Urban100 and 39.12 on Manga109, but its Set5 score of 38.14 is just below LatticeNet at 38.15.
At ×4, SwinIR has 897K parameters and 49.6G operations and reaches 32.44 on Set5. LatticeNet at ×4 has 777K parameters and 43.6G operations and scores 32.30, so SwinIR is slightly larger in this setting.
The authors state that SwinIR outperforms the compared lightweight methods by up to 0.53 dB PSNR across benchmarks while its counts stay similar. The maximum is not tied to one pair in the units, so the claim is read as a range over all entries.
Real-world super-resolution without ground truth
For real-world SR, SwinIR is retrained with the degradation model of BSRGAN, which creates the low-quality training inputs. The training losses combine pixel, GAN and perceptual terms, as described for real-world training.
No ground-truth high-quality images exist for these inputs, so the comparison is visual only, against ESRGAN, RealSR, BSRGAN and Real-ESRGAN. The authors say that SwinIR produces clear, sharp edges while the other methods show artifacts. No score supports this claim.
The authors also mention a larger model trained on much larger data, which they say handles more complex corruptions, with details given on a project page rather than in the text.
JPEG artifact reduction results
Classic5 and LIVE1 are tested at JPEG quality factors 10, 20, 30 and 40. The compared methods are ARCNN, DnCNN-3, QGAC, RNAN, RDN and DRUNet, and the metrics are PSNR, SSIM and PSNR-B.
Averaged across the quality factors, SwinIR exceeds the compared methods by at least 0.11 dB on Classic5 and 0.07 dB on LIVE1.
The window size is 7 for this task, not 8, because the authors saw a clear drop with window size 8 and suspect that the 8×8 JPEG block structure is the reason.
Grayscale and color denoising results
Grayscale denoising at noise levels 15, 25 and 50 is compared with BM3D, WNNM, DnCNN, IRCNN, FFDNet, N3Net, NLRN, FOCNet, RNAN, MWCNN and DRUNet on Set12, BSD68 and Urban100.
The authors report that SwinIR surpasses DRUNet by up to 0.3 dB on Urban100, which has 100 high-resolution test images, while using 12.0M parameters against 32.7M for DRUNet.
Color denoising uses CBSD68, Kodak24, McMaster and Urban100 against a longer list of color denoisers, including DRUNet and IPT. SwinIR scores 35.61 on McMaster at noise level 15, against 35.40 for DRUNet. Not every color entry favours SwinIR. On Kodak24 at noise level 50 it scores 29.79, slightly below DRUNet at 29.86.
The visual comparisons for grayscale and color denoising show SwinIR keeping edges and texture where other methods over-smooth or over-sharpen. This is a qualitative reading of the figures.
Limitations
Real-world super-resolution is assessed only visually, because no ground-truth high-quality images exist for those inputs.
The ablations train on DIV2K and test on Manga109 at ×2 only, and the convergence curves cover that single comparison. The authors suggest the 1×1 convolution result reflects its inability to capture local neighbourhood information, but they do not test that explanation separately.
The IPT entries rest on ImageNet training with more than 1.3 million images and 115.5M parameters, which differs from the DIV2K-only SwinIR settings, and the authors state that IPT depends on large parameter counts, large datasets and multi-task learning.
Training and evaluation details are placed in the supplementary material, so the main text gives only the settings that change the meaning of the results. Lightweight super-resolution does not lead on every benchmark entry, as the Set5 ×2 result shows.
Deblurring and deraining are not tested, and the authors list them as future work.
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}
}