Appearance
Training Pipeline
This guide covers dataset layout, synthetic degradation setup, multi-GPU distributed training, and checkpoint selection.
1. Dataset Preparation
Organize paired HR/LR datasets or HR-only corpora (for on-the-fly degradation) under a shared data root:
text
datasets/
├── DF2K/
│ ├── HR/ # High-resolution PNG/WebP ground truth
│ └── LR_bicubic/X4/ # Optional precomputed bicubic LR pairs
└── benchmarks/
├── Set5/
├── Set14/
├── Urban100/
└── Manga109/For fast random patch sampling on NVMe drives, pre-slice large images (> 2000 px) into overlapping 512 × 512 sub-images to eliminate PNG decode bottlenecks:
bash
sorasr data prepare-subimages \
--input datasets/DF2K/HR \
--output datasets/DF2K/HR_sub512 \
--crop-size 512 \
--step 384 \
--workers 162. Second-Order Blind Degradation
For real-world restoration beyond clean bicubic downsampling, enable SoraSR's second-order degradation pipeline in your training YAML:
- Pass 1: Anisotropic Gaussian / generalized Gaussian blur → random resize (area, bilinear, bicubic) → Gaussian or Poisson noise → JPEG compression (
q ∈ [50, 95]). - Pass 2: Mild re-blurring → final target downscale → optional sinc ringing filter to emulate sharpening halos.
3. Distributed Data Parallel (DDP) Training
Launch a 4-GPU training run with torchrun:
bash
torchrun --nproc_per_node=4 -m sorasr.cli train \
--config configs/train_sorasr_b_x4.yaml \
--work-dir runs/sorasr_b_x4_stage1 \
--precision bf16Stability Practices
- Exponential Moving Average (EMA) — Maintain shadow weights with decay
0.999(ema.enabled: true). Always evaluate and export the EMA checkpoint; it typically improves validation PSNR by0.08–0.15 dB. - Gradient Clipping — Clip global L2 norm to
1.0(optim.grad_clip: 1.0) to prevent rare outlier patches from destabilizing attention layers. - Cosine Annealing with Warmup — Linearly ramp learning rate from
1e-6to2e-4over the first 2,000 iterations, then decay smoothly to1e-6.
4. Resuming & Fine-Tuning
Resume an interrupted run preserving optimizer state, scheduler step, and RNG seeds:
bash
sorasr train \
--config configs/train_sorasr_b_x4.yaml \
--work-dir runs/sorasr_b_x4_stage1 \
--resume autoTo initialize Stage 2 perceptual fine-tuning from a Stage 1 EMA checkpoint (resetting optimizer state):
bash
sorasr train \
--config configs/finetune_sorasr_b_x4_perceptual.yaml \
--init-weights runs/sorasr_b_x4_stage1/checkpoints/best_ema.pt \
--work-dir runs/sorasr_b_x4_stage2