How kaldwin0106/dr2_drgradation_remover works
Project type and purpose
• This is a research‐oriented two‐stage image‐processing pipeline for blind face restoration.
• Stage 1 (“DR2”) is a diffusion‐based degradation remover that produces a clean intermediate face image.
• Stage 2 (“Enhancement Module”) is a plug‑and‑play blind face restoration network (SPARNetHD by default) that upsamples and refines the intermediate image to high resolution.
File structure
• DRDR/: all code for the diffusion‑based degradation remover (UNet backbone, diffusion scheduler, loss functions, resizer, utilities).
• SPAR/: SPARNetHD implementation (network blocks, model definition, wrapper script).
• demo.py: orchestrates the two stages over a set of input directories, storing outputs in test_images/output.
• data.py: data loader and preprocessing for input images.
• dr2e.py: entry point that can be used as a library or CLI.
• weights/: placeholder for downloaded pre‑trained checkpoints for DR2 and SPARNetHD.
• test_images/: sample inputs and output directories.
Key insights from README
• Two control parameters for diffusion (“N” and “τ”) are chosen per input batch.
• The pipeline is implemented in PyTorch and builds upon existing open‑source code (ILVR_adm for DR2 and Face‑SPARNet for enhancement).
Main components
a. Data Ingestion
• Input images loaded by data.py
• Directory structure (“test_images/input/..”)
b. Stage 1: DR2 Degradation Remover
• DRDR blocks: UNet, diffusion scheduler (space_diffusion.py, diffusion.py), loss.py
• Configurable control parameters (N, τ)
• Pre‑trained DR2 checkpoint
• Outputs intermediate clean image (x̂₀) to “test_images/output/dr2/”
c. Stage 2: Enhancement Module
• SPARNetHD (SPAR folder) or any plug‑in model (VQFR, CodeFormer, GPEN)
• Takes x̂₀ as input, applies upsampling and refinement
• Uses SPARNetHD checkpoint by default
• Outputs final high‑resolution restored images (“test_images/output/final/”)
d. Auxiliary Modules
• demo.py: orchestration script driving both stages in sequence
• dr2e.py: library/API entry point for embedding this pipeline in other code
Relationships and interactions
• Data Loader → DR2 module → Intermediate Storage → Enhancement module → Final Output
• Both DR2 and Enhancement modules depend on PyTorch and require loading specific checkpoint files from weights/
• demo.py orchestrates parameter selection, checkpoint loading, model invocation, and writing results
Architectural patterns and design principles
• Modular pipeline: clear separation between degradation removal and enhancement stages
• Config-driven: diffusion control (N, τ) is parameterized per input directory
• Re‑use of open‑source modules: ILVR_adm and Face‑SPARNet codebases adapted
Essential architectural elements
• Parameters (N, τ) flowing into the DR2 module.
• A callout for dr2e.py as “API/library interface”