MidnightRunner/Misc 是超分模型集合(ESRGAN/RealESRGAN/SwinIR 等 100+ 模型)。 本适配选取代表性模型 RealESRGAN_x4plus(RRDBNet,16.7M 参数)做 NPU 推理: 给定低分辨率图像,4× 超分辨率重建。
Misc 集合为混合格式超分模型(.pth/.safetensors),非 transformers 模型。 各模型架构不同,本适配以 RealESRGAN_x4plus 为代表证明该模型类型可在 NPU 上运行; 集合内其他 ESRGAN 系模型(4x_UltraSharp 等)使用相同 RRDBNet 架构,可复用本方法。
| 项目 | 值 |
|---|---|
| 模型 | MidnightRunner/Misc(RealESRGAN_x4plus.pth) |
| 架构 | RRDBNet(23 个 RRDB 块,ESRGAN) |
| 参数量 | 16.7M |
| 输入 | 低分辨率 RGB 图像 (1,3,H,W),[0,1] |
| 输出 | 4× 超分辨率图像 (1,3,4H,4W) |
| 许可证 | Apache-2.0 |
| 精度 | float32 |
source /usr/local/Ascend/ascend-toolkit/set_env.sh)export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch torch_npu numpy Pillow权重(RealESRGAN_x4plus.pth 67MB)从 Hugging Face 获取:
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download MidnightRunner/Misc RealESRGAN_x4plus.pth --local-dir model_srcpython3 inference.py --model_path . --device npu:0可选参数:--input <img>(图像文件)、--output <sr.npy>(保存 SR 结果)
输出示例(64×64 合成测试图 → 256×256):
[info] load_state_dict: missing=0 unexpected=0
[info] model loaded, params=16.7M device=npu:0
[info] input (1, 3, 64, 64) device npu:0
[info] Inference complete (69.7 ms)
[result] output shape (256, 256, 3) (4x upscale from 64x64)
[result] SR stats: mean=0.3472 std=0.2502 range=[0.0000, 0.9828]
[info] device proof: model on npu:0load_state_dict 0/0 加载,4× 超分前向在 npu:0 上执行)torchvision.transforms.functional_tensor 已移除),故将 RRDBNet 架构提取为独立文件
rrdbnet_arch.py(纯 PyTorch,无外部依赖)。params_ema 状态字典,直接加载到 RRDBNet。.to("npu:0") 迁移。├── inference.py # NPU 推理脚本
├── rrdbnet_arch.py # RRDBNet 架构定义(独立)
├── RealESRGAN_x4plus.pth # 权重(不推送)
├── README.md # 本模型卡片
└── assets/ # 截图素材@article{wang2021real,
title={Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
author={Wang, Xintao and others},
journal={ICCV Workshops},
year={2021}
}