Real-ESRGAN
A practical blind super-resolution upscaler trained on synthetic degradations rather than only bicubic downscaling. LibreYOLO ships inference and validation for its 4x, 2x and fast 4x checkpoints.
- Tasks
- restore
- Sizes
- x4, x2, x4t at 64 px
- Install
pip install libreyolo- Support tier
- Inference only, since v. Predict, validate and export only. Training features do not apply.
- Upstream
- Real-ESRGAN by Tencent ARC Lab and Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences, BSD-3-Clause. Paper, source
- Licenses
- Code Apache-2.0 and BSD-3-Clause, weights BSD-3-Clause. Commercial use
Install
Real-ESRGAN needs no optional extra. Everything it imports is in the base install.
pip install libreyoloPredict
Weights download from Hugging Face on first use and are cached locally.
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreRealESRGANx4-restore.pt")result = model(SAMPLE_IMAGE, save=True) restored = result.restoredprint(restored.array.shape, restored.array.dtype)libreyolo predict model=LibreRealESRGANx4-restore.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=Truefrom libreyolo import LibreYOLO model = LibreYOLO("LibreRealESRGANx4-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=10, save=True)A restore result carries no boxes; result.restored is a dense (H, W, 3)
uint8 RGB image, on a canvas Results.restore_scale times the input in each
dimension. save=True writes that image directly rather than an annotated
plot. Input is converted to RGB and any alpha channel is dropped. 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 checkpoints, named for their upscale factor. x4 is RRDBNet
(RealESRGAN_x4plus), 23 residual-in-residual dense blocks, the quality
default at 4x. x2 is the same RRDBNet architecture at 2x. x4t is
SRVGGNetCompact (realesr-general-x4v3), a smaller, faster generator built for
video and lower-latency use at 4x. The upstream general-purpose model also
ships a paired denoise-strength network blended in at inference time; that
strength knob is not part of this port, which runs the base x4t generator.
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.
from libreyolo import LibreYOLO model = LibreYOLO("LibreRealESRGANx4-restore.pt")metrics = model.val(data="my-restore-dataset.yaml") print(metrics["metrics/PSNR"])print(metrics["metrics/SSIM"])libreyolo val model=LibreRealESRGANx4-restore.pt data=my-restore-dataset.yamlThe 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
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| restore | restore to ONNX: supported. | restore to TorchScript: supported. | restore to ExecuTorch: supported. | restore to TensorRT: supported. | restore to OpenVINO: supported. | restore to Paddle: not supported | restore to MNN: not supported | restore to RKNN: not supported | restore to ncnn: supported. | restore to TFLite: supported. | restore to CoreML: not supported | restore to Core AI: 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. Export lists the arguments every format accepts and
the extras a few of them add.
from libreyolo import LibreYOLO model = LibreYOLO("LibreRealESRGANx4-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)libreyolo export model=LibreRealESRGANx4-restore.pt format=onnx imgsz=512from 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("LibreRealESRGANx4-restore.onnx")result = model(SAMPLE_IMAGE) print(result.restored.array.shape)Checkpoints
Every published weight file for this family.
| File | Input (px) | Weights license |
|---|---|---|
| restore | ||
| LibreRealESRGANx4t-restore.pt | bsd-3-clause | |
| LibreRealESRGANx4-restore.pt | bsd-3-clause | |
| LibreRealESRGANx2-restore.pt | bsd-3-clause | |
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
- Real-ESRGAN, Tencent ARC Lab and Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
- Upstream license
- BSD-3-Clause
- Upstream source
- github.com/xinntao/Real-ESRGAN
- LibreYOLO code
- MIT
- Weights
- BSD-3-Clause, republished at huggingface.co/LibreYOLO
- Interpretation
- BSD-3-Clause is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep the copyright notice, the condition list and the disclaimer with any copy you redistribute, in source or compiled form, and its third clause forbids using the names of Xintao Wang or the project's contributors to endorse or promote a derived product without separate written permission. It carries no patent grant, unlike Apache-2.0. LibreYOLO's checkpoints are format conversions of the official pretrained generators, with the learned parameters unchanged; Real-ESRGAN's training is a GAN over a synthetic degradation pipeline that is not wired into this library, so there is no LibreYOLO-trained variant to license separately.
Citation
@InProceedings{wang2021realesrgan,
author = {Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan},
title = {Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
booktitle = {International Conference on Computer Vision Workshops (ICCVW)},
date = {2021}
}Copied from the authors' citation block at github.com/xinntao/Real-ESRGAN#bibtex.