2
gcw_BOxvkDDf/midnightrunner-misc
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MidnightRunner/Misc — RealESRGAN_x4plus on Ascend NPU

Ascend NPU (torch_npu) adaptation of the RealESRGAN_x4plus.pth checkpoint from the Hugging Face bucket MidnightRunner/Misc.

The source repo is a large bucket of many unrelated checkpoints (super-resolution models, SAM, ComfyUI LoRAs, GGUF LLMs, …) with no single config.json. Scope: the single canonical Real-ESRGAN x4plus super-resolution model (RRDBNet, 4× upscaling, ~64 MB).

Artifact

  • Weight: RealESRGAN_x4plus.pth (canonical Real-ESRGAN x4, RRDBNet, num_feat=64, num_block=23, num_grow_ch=32, scale=4, RGB 3→3 channels).
  • The checkpoint wraps the state dict under params_ema; the 702 inner keys load strictly into the self-contained RRDBNet in model.py (no basicsr/realesrgan dependency).

Project layout

model.py        Self-contained RRDBNet + NPU device helper + weight loader + inference
inference.py    Dual-mode entry point (CLI + FastAPI)
requirements.txt
model_weights/MidnightRunner/Misc/RealESRGAN_x4plus.pth   (downloaded, gitignored)
input/          sample low-res images
outputs/        upscaled results
assets/         verification screenshots

Requirements

  • Python 3.11, PyTorch 2.9.0 + torch_npu 2.9.0 (Ascend910), CANN toolkit
  • pillow, numpy, fastapi, uvicorn, python-multipart

Install deps:

pip install -i https://repo.huaweicloud.com/repository/pypi/simple/ pillow numpy fastapi uvicorn python-multipart

Weights auto-download (only the single .pth, not the whole bucket) to ./model_weights/MidnightRunner/Misc/ on first run, cached thereafter.

CLI usage

4× super-resolution of a single image:

source /usr/local/Ascend/ascend-toolkit/set_env.sh
python3 inference.py --img input/sample_lowres.png     # --input is an alias

Output: outputs/<name>_x4.png. stdout prints the output size and pixel stats (mean/std/min/max). Device is selected by get_device(): npu:1 (assigned physical NPU 1) with automatic CPU fallback if NPU init fails.

FastAPI usage

python3 inference.py --serve     # uvicorn on 0.0.0.0:8000
  • GET / → HTML upload form
  • POST /predict → multipart image upload; returns JSON {model, artifact, device, input_size, output_size, output_path, mean_std, min_max} and saves the upscaled PNG to outputs/.

Example:

curl -s -X POST http://0.0.0.0:8000/predict -F "file=@input/sample_lowres.png"

Verification (Ascend NPU)

[device] inference device = npu:1
[infer] output size: 256x256 (4x upscale, device=npu:1)
[infer] pixel stats -> mean=0.5301 std=0.3040 min=0.0000 max=1.0000

The 64×64 sample input is upscaled to 256×256 on npu:1 (exit 0). Screenshots in assets/ capture the real logs and the FastAPI JSON response.

Notes

  • No CUDA device calls anywhere in the project (spec: grep -rin cuda → clean).
  • Residual scaling in RDB/RRDB is 0.2 as trained in the canonical Real-ESRGAN x4plus checkpoint (the generic RRDB paper formula uses 1/√3, but the trained weights use 0.2).
  • Upsampling is the canonical F.interpolate(scale_factor=2, mode='nearest') + conv, matching the checkpoint's conv_up1/conv_up2 weights.