SwinIR

A Swin Transformer network for image restoration. LibreYOLO ships inference and validation for its 4x super-resolution checkpoints: the official lightweight, real-world medium and real-world large generators.

Tasks
restore
Sizes
s, m, l at 64 px
Install
pip install libreyolo
Support tier
Inference only, since v. Predict, validate and export only. Training features do not apply.
Upstream
SwinIR by Computer Vision Lab, ETH Zurich, Apache-2.0. Paper, source
Licenses
Code Apache-2.0, weights Apache-2.0. Commercial use

Install

SwinIR needs no optional extra. Everything it imports is in the base install.

bash
pip install libreyolo

Predict

Weights download from Hugging Face on first use and are cached locally.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreSwinIRm-restore.pt")result = model(SAMPLE_IMAGE, save=True) restored = result.restoredprint(restored.array.shape, restored.array.dtype)
CLI
libreyolo predict model=LibreSwinIRm-restore.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
Tiled, for large images
from libreyolo import LibreYOLO model = LibreYOLO("LibreSwinIRl-restore.pt") # tile splits the forward pass into overlapping tiles and blends the# seams back together; tile_pad is the halo added around each tile# before it is cropped back out. Both are Python-only keyword# arguments, not CLI flags.result = model("large-photo.jpg", tile=512, tile_pad=16, save=True)

A restore result carries no boxes; result.restored is a dense (H, W, 3) uint8 RGB image, on a canvas 4x the input in each dimension. save=True writes that image directly rather than an annotated plot. The input is padded to a multiple of 8 rather than resized, so predict runs at the photo's own resolution; a source larger than memory allows can be split with tile and tile_pad, which blend the tile seams back together in the output. See prediction for sources, streaming and result handling.

Variants

Three sizes, all fixed at a 4x upscale. s is the official lightweight generator, with four residual Swin Transformer block (RSTB) stages and pixel-shuffle-direct upsampling. m and l are the real-world medium and large generators, with six and nine RSTB stages and a nearest-neighbor-plus- convolution upsampler built for real-world degradations rather than only bicubic downscaling.

Validate

val() measures PSNR and SSIM between the restored output and a clean target image, both computed in RGB on the original canvas with no border crop and no resizing. SSIM uses an 11x11 Gaussian window with sigma 1.5, averaged over the three color channels.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSwinIRm-restore.pt")metrics = model.val(data="my-restore-dataset.yaml") print(metrics["metrics/PSNR"])print(metrics["metrics/SSIM"])
CLI
libreyolo val model=LibreSwinIRm-restore.pt data=my-restore-dataset.yaml

The dataset argument is a YAML pairing a directory of degraded input images with a directory of clean target images of matching resolution; see dataset formats for the exact keys.

Export

TaskONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
restorerestore to ONNX: supported. restore to TorchScript: supported. restore to ExecuTorch: not supportedrestore to TensorRT: supported. restore to OpenVINO: supported. restore to Paddle: not supportedrestore to MNN: not supportedrestore to RKNN: not supportedrestore to ncnn: not supportedrestore to TFLite: supported. restore to CoreML: not supportedrestore to Core AI: not supported

An exported artifact loads back through LibreYOLO() on its file suffix, so a .onnx or .engine file behaves like a checkpoint and returns the same Results. ExecuTorch and every format the matrix marks blocked are not available for this family; ONNX, TorchScript, TensorRT, OpenVINO and TFLite are. Export lists the arguments every format accepts and the extras a few of them add.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSwinIRm-restore.pt") # imgsz defaults to a small internal patch size when omitted, not# your working resolution, so pass the size your deployment actually# feeds the model.model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True)
CLI
libreyolo export model=LibreSwinIRm-restore.pt format=onnx imgsz=512
Use the exported file
from libreyolo import LibreYOLO, SAMPLE_IMAGE # The factory routes on the file suffix, so an exported artifact loads# like any checkpoint and returns the same Results object.model = LibreYOLO("LibreSwinIRm-restore.onnx")result = model(SAMPLE_IMAGE) print(result.restored.array.shape)

Checkpoints

Every published weight file for this family.

FileInput (px)Weights license
restore
LibreSwinIRs-restore.ptapache-2.0
LibreSwinIRm-restore.ptapache-2.0
LibreSwinIRl-restore.ptapache-2.0

Every file above exists in the LibreYOLO org today and downloads on first use.

Licensing

Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.

This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.

Original work
SwinIR, Computer Vision Lab, ETH Zurich
Upstream license
Apache-2.0
LibreYOLO code
MIT
Weights
Apache-2.0, republished at huggingface.co/LibreYOLO
Interpretation
Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code. LibreYOLO's checkpoints are format conversions of the official pretrained generators, with the learned parameters unchanged; SwinIR's real-world variants need a degradation and GAN training pipeline that is not wired into this library, so there is no LibreYOLO-trained variant to license separately.

Citation

@article{liang2021swinir,
  title={SwinIR: Image Restoration Using Swin Transformer},
  author={Liang, Jingyun and Cao, Jiezhang and Sun, Guolei and Zhang, Kai and Van Gool, Luc and Timofte, Radu},
  journal={arXiv preprint arXiv:2108.10257},
  year={2021}
}

Copied from the authors' citation block at github.com/JingyunLiang/SwinIR#citation.

Verified against LibreYOLO v1.5.0. Support tables, checkpoints and benchmark numbers on this page are generated from the released library and the published weights, not written by hand.