Projects / LeafSR
LeafSR
Plant leaf super-resolution with an ESRGAN-lite conditional GAN, RRDB blocks, EMA checkpoints, and CI smoke tests.
- PyTorch
- GANs
- Docker
Demo
Overview
LeafSR is a PyTorch super-resolution pipeline for plant leaf images. It enlarges low-resolution leaf photos 4x by predicting the fine detail that bicubic interpolation misses, and it turns a Kaggle-style notebook into a reproducible project with training, inference and comparison scripts.
The model is an ESRGAN-lite conditional GAN. A generator built from Residual-in-Residual Dense Blocks predicts a residual on top of the bicubic image, and it is trained with a mix of pixel, perceptual, frequency and adversarial losses.
On held-out images it lowers the mean absolute error from 18.20 (bicubic) to 16.89, a 7.2% reduction. The demo below is a recording of the project's own live site, which shows three real paired samples and predictions from the trained checkpoint.
What it does
- ESRGAN-lite generator. Residual-in-Residual Dense Blocks with pixel-shuffle upsampling, predicting a residual over the bicubic image.
- Conditional discriminator. It sees the bicubic image together with the real or generated high-resolution image.
- Hybrid objective. Charbonnier, residual, VGG perceptual, FFT and adversarial losses combined.
- Careful training. CUDA mixed precision, a cosine schedule, gradient clipping, EMA-smoothed weights and early stopping.
- Inference. Eight-way test-time augmentation and an optional top-k checkpoint ensemble, writing PNGs or a Kaggle-style submission CSV.
- Reproducible. YAML config, a Docker image, smoke tests and CI, plus scripts to prepare data and build comparison grids.
Screenshots




How it works
- Low- and high-resolution leaf images are matched by filename and cropped into aligned patches with random flips and rotations.
- Each patch is upsampled 4x with bicubic interpolation, and the RRDB generator predicts a residual that is added on top.
- A hybrid loss keeps the output faithful, and a low-weight adversarial term from a conditional discriminator sharpens texture.
- Mixed-precision training with a cosine schedule keeps EMA-smoothed checkpoints and stops early when validation stops improving.
- At inference, eight flipped and rotated variants are averaged and written out as images or a submission file.
Install and try it
LeafSR needs Python 3 and PyTorch. The competition dataset is not included in the repository, so a full run needs the original data in data/.
- Set it up
git clone https://github.com/BriskAM/leafsr.git cd leafsr python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt - Prepare the data
python scripts/prepare_data.py plant-leaves-super-resolution-challenge.zip --out-dir data - Train
python scripts/train.py --config configs/default.yaml - Enhance images
Use
scripts/make_comparison.pyto build low-res / bicubic / prediction / target grids like the one above.python scripts/infer.py \ --checkpoint runs/leafsr/best_leafsr.pt \ --input-dir data/test_Low_Resolution \ --output-dir runs/leafsr/predictions
Notes
- The dataset, VGG weights and checkpoints are kept out of git, so the demo uses three committed paired samples and predictions precomputed from the trained checkpoint.
- Validation error is the mean absolute error on held-out training images. The original run used a Tesla T4 with mixed precision.
- The project site (linked below) is a live, interactive version of this demo.