How cszn/usrnet works
Project type and purpose
• This is a research-oriented Python library for non-blind single image super-resolution (SISR) using a deep unfolding network (USRNet).
• It provides evaluation scripts, pretrained models, blur‐kernel definitions, and core modules: data‐term solver, ResUNet prior, and hyper-parameter MLP.
Top‐level file structure and architectural implications
• main_*.py scripts: entry points for different test scenarios (Table1, bicubic, real application) and model download.
• models/: contains network definitions (network_usrnet.py, network_usrnet_v1.py) and building block (basicblock.py).
• utils/: image I/O, kernel handling, deblurring and SISR helper functions, logging utilities.
• kernels/: MATLAB .mat files defining blur kernels (Gaussian, bicubic).
• model_zoo/: pretrained weights and their README.
• testsets/: input images grouped by dataset (Set5, Set_real).
• figs/: sample input/output visuals used in the paper and README.
Core components
a. CLI & Orchestrator
• Entry scripts (main_test_*.py, main_download_pretrained_models.py) parse arguments (LR image path, kernel file, scale factor, noise σ, iteration count).
• They load configuration and call the USRNet pipeline.
b. Input layer
• LR image loader (via utils_image.py)
• Blur kernel loader (via utils_deblur.py reading .mat)
• Noise level & scale factor parameters
c. Hyper-parameter module (H)
• A small MLP in network_usrnet.py that outputs per-iteration weights controlling data/prior fusion.
d. Data module (D)
• A closed-form solver for the data consistency subproblem (no trainable parameters).
e. Prior module (P)
• A ResUNet denoiser implemented in network_usrnet.py using building blocks from basicblock.py.
f. Iteration loop
• Fixed number of unfolding iterations (e.g., 8).
• In each iteration, feed current estimate into Data module D and Prior module P, combine via H’s outputs.
g. Output & post-processing
• Final HR image saved via utils_image.py
• PSNR/SSIM metrics computed (in test scripts) and logged via utils_logger.py.
External dependencies
• PyTorch (model definitions, tensor ops, DataParallel/DistributedDataParallel)
• SciPy (loading .mat blur kernels)
• NumPy (numerical ops)
• PIL/OpenCV (image read/write)
Relationships and data flow
• Side inputs: model weights loaded from model_zoo/; kernel files from kernels/; test images from testsets/.
• Configuration JSON (in KAIR training code, outside this repo) can be noted as an extension point.
Architectural patterns and design principles
• Modular decomposition: separation of data consistency (D), prior denoiser (P), hyper-parameter controller (H).
• Iterative unfolding: explicit loop structure in the pipeline.
• Extensibility: additional scripts can plug into the same pipeline; new kernels/models can be added to kernels/ and models/.
• Configurability: CLI arguments drive behavior; MLP weights adapt to different scales/kernels/noise.