Models · Image restoration

SwinIR

SwinIR (Liang et al., ICCVW 2021): a Swin Transformer upscaler: x4 / x2 for clean (bicubic) images and x4 for real-world photos (medium and large). Apache-2.0 code and weights.

experimental Fork of JingyunLiang/SwinIR@6545850 · backends: portable, kernels

Checkpoint

Paper 2021 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 576 ms 512x512, fp16
vs the faster original 6.1× original fp16: 3497 ms
Peak memory 1,354 MiB original: 1,500 MiB
Accuracy vs original fp32 −0.01 kernels psnr, DIV2K validation (every 2nd: 50 images) (30.90 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import restoration

model = restoration.load("swinir-m-x4")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench swinir-m-x4

Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.

Speed and memory

Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.

Input: synthetic, 512x512 (the task’s standard size)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16.half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tilefp16 3497–1,500 MiB/2,058 MiB1.62.86
Portable fp32fp32not measured ––––
Portablefp16 7674.6×1,499 MiB/2,054 MiB0.60.77
Kernelsfp16 5766.1×1,354 MiB/1,456 MiB0.70.64
Portable + torch.compile 7954.4×1,684 MiB/1,796 MiB62 (build)–
TensorRT fp16fp16 7274.8×5,270 MiBenginenot comparable104 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 to 2026-11-15. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.

Other devices

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp328782 7,699 MiB process–512x512
Portablefp165893 5,060 MiB processmatches512x512
Portablefp326506 8,392 MiB processmatches512x512
Kernelsfp16not implemented–512x512

CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.

Licence and weights

Commercial use allowed

Code
Apache-2.0 LICENSE
Weights
Apache-2.0 source
Training data

Our reading of the licences, not legal advice.

Weights

001_classicalSR_DF2K_s64w8_SwinIR-M_x4.pth 67.9 MB· hosted on GitHub

fastforks downloads and checks these files on first use (fastforks download swinir-m-x4).

Accuracy

The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.

DIV2K validation (every 2nd: 50 images)

bicubic x4 LR -> HR, PSNR / SSIM (Y)

Rundtypepsnr ↑ssim ↑Δ psnr vs fp32 originalimagesms / image
Original fp32fp3230.900.8423 reference 50 –
Original fp16not measured
Portable fp32fp3230.900.8423 ±0.00 50 –
Portablefp1630.900.8423 ±0.00 50 –
Kernelsfp1630.890.8422 −0.01 50 –

DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, `scale` px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.

Closeness to the original

Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 1.4e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output image).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.000014 not recorded
GPU default dtypes, mean |diff|≤ 0.02 0.00052
GPU default dtypes, p99 |diff|≤ 0.25 0.00192

Recorded for swinir-m-x4 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_hacc

Details

SwinIR (Liang et al., ICCVW 2021): image restoration with residual groups of Swin Transformer layers (8 x 8 window attention, shifted every second layer) between a conv stem and an upsampler. `swinir-m-x4` / `swinir-m-x2` are the classical (bicubic, PSNR-trained) DF2K models, `swinir-m-x4-real` and `swinir-l-x4-real` the real-world x4 GAN models (BSRGAN degradations; L = 9 groups, 240 channels).

Input / output
Input: one RGB image. Output: the restored (upscaled) image, model.scale x the input size, RGB in [0, 1].
What the numbers mean, and which models need the camera focal length

tile= runs large images in overlapping tiles (as ComfyUI).

Input size
any H x W >= 32, padded to a multiple of 32; tested up to 1024x1024 (11.0 GiB allocated)
Outputs
image
CUDA kernels
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

SwinIR (Liang et al., ICCVW 2021): a Swin Transformer upscaler: x4 / x2 for clean (bicubic) images and x4 for real-world photos (medium and large). Apache-2.0 code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
swinir-m-x4synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
3497
767
576
795
727
1500 / 2058
1499 / 2054
1354 / 1456
1684 / 1796
5525 / 5604
swinir-m-x2synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
3252
739
553
781
719
1500 / 1818
1353 / 1454
1353 / 1454
1683 / 1796
5088 / 5144
swinir-m-x4-realsynthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
2462
1242
584
807
733
2321 / 2978
2387 / 3034
1353 / 1814
1683 / 1796
5427 / 5506
swinir-l-x4-realsynthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
3709
2099
1036
1426
1118
2357 / 2746
2425 / 2672
1806 / 1934
2153 / 2876
9182 / 9282
Details
  • Original code: https://github.com/JingyunLiang/SwinIR at 6545850fbf8d
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/JingyunLiang/SwinIR/blob/6545850fbf8df298df73d81f3e8cba638787c8bd/LICENSE ; https://github.com/JingyunLiang/SwinIR/releases/tag/v0.0
  • Training data: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (README, Training and testing: classical SR on DF2K (DIV2K + Flickr2K) HR images, bicubic-downsampled.)
    • swinir-m-x4-real: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR), OutdoorSceneTraining (OST, SFTGAN) (README, Training and testing: real-world SR, SwinIR-M on DIV2K + Flickr2K + OST HR images with BSRGAN degradations.)
    • swinir-l-x4-real: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR), OutdoorSceneTraining (OST, SFTGAN), Waterloo Exploration Database (4744 natural images), Flickr-Faces-HQ (FFHQ, 70k face images), Manga109 (109 Japanese manga volumes), SCUT-CTW1500 (curved scene text) (README, Training and testing: real-world SR, SwinIR-L on DIV2K + Flickr2K + OST + WED + FFHQ (first 2000) + Manga109 + SCUT-CTW1500 (first 100) with BSRGAN degradations.)
  • Kernel libraries: cudnn_hacc
  • Variants: swinir-m-x4, swinir-m-x2, swinir-m-x4-real, swinir-l-x4-real
  • Outputs: image
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): swinir-m-x4 1024x1024 (11.0 GiB peak allocated, 14.4 reserved); swinir-m-x2 1024x1024 (11.0 GiB peak allocated, 12.3 reserved); swinir-m-x4-real 512x512 (3.1 GiB peak allocated, 5.6 reserved); swinir-l-x4-real 512x512 (4.0 GiB peak allocated, 5.8 reserved)
  • swinir-m-x4 512x512, first call: portable + torch.compile 62 s (cold Inductor cache), TensorRT fp16 104 s (ONNX + engine).
  • swinir-m-x2 512x512, first call: portable + torch.compile 60 s (cold Inductor cache), TensorRT fp16 102 s (ONNX + engine).
  • swinir-m-x4-real 512x512, first call: portable + torch.compile 60 s (cold Inductor cache), TensorRT fp16 109 s (ONNX + engine).
  • swinir-l-x4-real 512x512, first call: portable + torch.compile 68 s (cold Inductor cache), TensorRT fp16 193 s (ONNX + engine).
  • swinir-m-x4 original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tile
  • swinir-m-x2 original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tile
  • swinir-m-x4-real original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tile
  • swinir-l-x4-real original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tile
  • swinir-m-x4 load / first call: original 2.07 s / 3.272 s, portable 0.44 s / 1.36 s, kernels 1.28 s / 0.646 s
  • swinir-m-x2 load / first call: original 2.95 s / 4.489 s, portable 0.67 s / 0.848 s, kernels 0.43 s / 0.629 s
  • swinir-m-x4-real load / first call: original 2.06 s / 3.326 s, portable 0.4 s / 1.386 s, kernels 1.31 s / 0.697 s
  • swinir-l-x4-real load / first call: original 2.15 s / 5.945 s, portable 0.7 s / 2.188 s, kernels 1.46 s / 1.103 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, scale px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32portableportable fp32kernelsnote
swinir-m-x4DIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)30.90 / 0.842330.90 / 0.842330.90 / 0.842330.89 / 0.8422
swinir-m-x2DIV2K validation (100 images), bicubic x2 LR -> HR, PSNR / SSIM (Y)36.86 / 0.950736.86 / 0.9507
swinir-m-x4-realDIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)26.71 / 0.751626.71 / 0.751626.71 / 0.751626.71 / 0.7515
swinir-l-x4-realDIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)27.04 / 0.762827.04 / 0.762827.04 / 0.762827.05 / 0.7628

Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3bf0bac7 / 45a5c91f, 2026-11-13 to 2026-11-18; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.

Parity

CPU, float32: max |diff| <= 1.4e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output image).

variantkernels error vs original, mean / p99GPU, torchkernels used
swinir-m-x40.00052 / 0.00192RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
swinir-m-x20.00039 / 0.00139RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
swinir-m-x4-real0.00126 / 0.00498RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
swinir-l-x4-real0.00082 / 0.0039RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400

Example output

No example rendered for this checkpoint yet.