查看 Markdown

Real-ESRGAN

一个实用的盲超分辨率放大模型,训练用的是合成退化,而不是只有双三次下采样。LibreYOLO 为它的 4x、2x 和快速 4x 检查点提供推理和验证。

任务
restore
尺寸
x4, x2, x4t at 64 px
安装
pip install libreyolo
支持层级
仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
上游
Real-ESRGAN,由 Tencent ARC Lab and Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences 发布,采用 BSD-3-Clause 许可。论文源码
许可
代码采用 Apache-2.0 and BSD-3-Clause,权重采用 BSD-3-Clause。商用

安装

Real-ESRGAN 不需要任何可选 extra。它导入的一切都在基础安装里。

bash
pip install libreyolo

预测

权重在首次使用时从 Hugging Face 下载,并缓存在本地。

Python
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)
CLI
libreyolo predict model=LibreRealESRGANx4-restore.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
分块处理大图
from libreyolo import LibreYOLO model = LibreYOLO("LibreRealESRGANx4-restore.pt") # tile 把前向过程切成互相重叠的分块,再把接缝混合回去;tile_pad 是每个# 分块在被裁回去之前,四周额外加的一圈边距。两者都只是 Python 的关键字# 参数,不是 CLI 标志result = model("large-photo.jpg", tile=512, tile_pad=10, save=True)

恢复类结果不带检测框;result.restored 是一张稠密的 (H, W, 3) uint8 RGB 图 像,画布在每个维度上都是输入的 Results.restore_scale 倍。save=True 会把这 张图像直接写入磁盘,而不是写一张画了标注的图。输入会被转成 RGB,任何 alpha 通 道都会被丢掉。超出内存承受范围的数据源可以用 tiletile_pad 切开,它们会 在输出里把分块的接缝混合回去。数据源、流式处理和结果处理见预测

变体

三个检查点(checkpoint),按放大倍数命名。x4 是 RRDBNet (RealESRGAN_x4plus),23 个残差中的残差稠密块,是 4x 下的画质默认选择。x2 是同样的 RRDBNet 架构,倍数为 2x。x4t 是 SRVGGNetCompact (realesr-general-x4v3),一个更小、更快的生成器,为视频和 4x 下延迟更低的用 法而设计。上游的通用模型还配套发布了一个去噪强度网络,在推理时混合进来;这个强 度旋钮不在这次移植的范围内,本移植跑的是基础的 x4t 生成器。

验证

val() 测量恢复输出和干净目标图像之间的 PSNR 和 SSIM,两者都在 RGB 上、按原始 画布计算,不裁边框也不做缩放。SSIM 用的是 11x11 的高斯窗口,sigma 为 1.5,在三 个颜色通道上取平均。

Python
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"])
CLI
libreyolo val model=LibreRealESRGANx4-restore.pt data=my-restore-dataset.yaml

数据集参数是一个 YAML,把一个存放退化输入图像的目录和一个存放同分辨率干净目标 图像的目录配成对;确切的键见数据集格式

导出

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
restorerestore to ONNX:支持restore to TorchScript:支持restore to ExecuTorch:支持restore to TensorRT:支持restore to OpenVINO:支持restore to Paddle:不支持restore to MNN:不支持restore to RKNN:不支持restore to ncnn:支持restore to TFLite:支持restore to CoreML:不支持restore to Core AI:支持

导出的产物按文件后缀经由 LibreYOLO() 重新加载,所以一个 .onnx.engine 文件的表现和检查点一样,返回同样的 Results导出列出了每种格 式都接受的参数,以及其中少数几种额外增加的参数。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreRealESRGANx4-restore.pt") # 省略 imgsz 时,默认用的是一个很小的内部 patch 尺寸,而不是你的工作分# 辨率,所以请传入部署时真正喂给模型的尺寸model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True)
CLI
libreyolo export model=LibreRealESRGANx4-restore.pt format=onnx imgsz=512
使用导出的文件
from libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreRealESRGANx4-restore.onnx")result = model(SAMPLE_IMAGE) print(result.restored.array.shape)

检查点

这个家族已发布的全部权重文件。

文件输入(px)权重许可
restore
LibreRealESRGANx4t-restore.ptbsd-3-clause
LibreRealESRGANx4-restore.ptbsd-3-clause
LibreRealESRGANx2-restore.ptbsd-3-clause

上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。

许可证

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
Real-ESRGAN, Tencent ARC Lab and Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
上游许可
BSD-3-Clause
LibreYOLO 代码
MIT
权重
采用 BSD-3-Clause 许可,重新发布在 huggingface.co/LibreYOLO
解读
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.

引用

@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}
}

复制自作者在 github.com/xinntao/Real-ESRGAN#bibtex 上提供的引用块。

已针对 LibreYOLO v1.5.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。