PyTorch Lightning training code for image super-resolution with a Swin2SR backbone.
- A training pipeline built on
pytorch-lightning - A Swin2SR model wrapper initialized from
caidas/swin2SR-realworld-sr-x4-64-bsrgan-psnr - Dataset support for:
- local PNG image folders
- LAION high-resolution data through Hugging Face Datasets
- Super-resolution specific losses and image quality metrics (PSNR, SSIM, MS-SSIM)
- Weights & Biases logging and checkpointing
src/super_resolution/
├── scripts/
│ ├── train.py # main training entrypoint
│ └── download_hf.py # helper script to download LAION HD images locally
├── modeling/
│ └── swin2sr/model.py # Swin2SR model wrapper
├── datasets/ # dataset implementations
├── datamodule.py # Lightning DataModule
├── lightning_module.py # training/validation logic
└── losses.py # custom SR losses
- Python 3.12+
- CUDA GPU recommended for training
pip install -e .uv syncPoint --data_root to a directory containing PNG files (recursively discovered).
If --data_root is omitted, training uses laion/laion-high-resolution via Hugging Face Datasets.
From the repository root:
python -m super_resolution.scripts.train <run_name>Examples:
# Train from LAION stream
python -m super_resolution.scripts.train sr-laion-exp1
# Train from local files
python -m super_resolution.scripts.train sr-local-exp1 --data_root /path/to/images
# Multi-GPU run
python -m super_resolution.scripts.train sr-ddp-exp --num_devices 2Useful flags:
--batch_size(default:8)--num_workers(default:8)--num_devices(default:1)--log_path(default:logs)--ckpt_pathto resume from a Lightning checkpoint--weights_pathto load model weights--debugto run W&B in offline mode--overfitto overfit a small subset for debugging
python -m super_resolution.scripts.download_hf /path/to/data_rootImages are saved under /path/to/data_root/laion_hd.
ruff check src
pytest- Training logs are written under
logs/<run_name>by default. - Validation currently attempts to push the model to Hugging Face Hub (
swin2sr-laion-hd) at validation end.- Authenticate first with
huggingface-cli loginif you want this upload behavior. - If you do not want automatic uploads, remove or gate the
push_to_hub(...)call insrc/super_resolution/lightning_module.py.
- Authenticate first with
This project is licensed under the terms in LICENSE.