Projects / LeafSR

LeafSR

Plant leaf super-resolution with an ESRGAN-lite conditional GAN, RRDB blocks, EMA checkpoints, and CI smoke tests.

Demo

A recording of the live project site: the dataset explorer switching between three real samples, then the system design and the measured result.

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

Screenshots

Four leaf crops side by side: low-res input, bicubic baseline, LeafSR output and high-res target
Real sample 0005: low-res input, bicubic baseline, LeafSR output and the high-res target.
LeafSR project site hero with headline numbers
The project site at a glance: 4x scale, 1,642 train pairs, 495 test images, 8-way TTA.
LeafSR system design section
System design: patch loader, ESRGAN-lite generator, hybrid objective and inference.
LeafSR measured result: 18.20 MAE bicubic versus 16.89 MAE LeafSR
Measured result: 18.20 MAE for bicubic against 16.89 for LeafSR, a 7.2% reduction.

How it works

Interactive diagram · 9 steps
pairs patches input output adversarial update best average Low-resolution and high-resolution leaf images that share filenames. The dataset itself is not committed to git; only a few small samples are, for the demo site.Paired images1,642 LR/HR pairs, 4x1 Pairs the files by name, samples aligned low/high-resolution patches, and applies random flips and rotations so the model sees varied crops each epoch.ƒPatch loaderaligned crops + flips2 A bicubic upsample of the low-resolution patch. It is both the baseline to beat (18.20 MAE) and the starting point the network improves on.Bicubic 4xclassical baseline3 An ESRGAN-lite generator built from Residual-in-Residual Dense Blocks with pixel-shuffle upsampling. It predicts a residual that is added to the bicubic image, so it only has to learn the missing detail.RRDB generatorpredicts a residual4 Charbonnier, residual, VGG perceptual and FFT losses plus a low-weight adversarial term. Pixel-style losses keep the output faithful, while perceptual and frequency terms recover texture.Hybrid loss5 terms combined5 A conditional discriminator sees the bicubic image together with either the real or generated high-resolution image, and supplies the adversarial signal at a low weight.Discriminatorconditional on bicubic6 Training uses mixed precision, a cosine schedule, gradient clipping and early stopping. Generator weights are smoothed with an exponential moving average, and the best checkpoints are kept.EMA checkpointstop-k, early stopping7 At inference each image is run through eight flipped and rotated variants and the results are averaged back together, which smooths out orientation-specific errors.ƒ8-way TTAflips x rotations8 The enhanced PNG, or a Kaggle-style submission CSV. On held-out images the mean absolute error drops from 18.20 for bicubic to 16.89, a 7.2% reduction.Enhanced image16.89 MAE (from 18.20)9
Pick a stepHover, focus or tap any shape to see what it does.
From paired images to an enhanced image. The dashed arrow is the adversarial signal from the discriminator. Editable source (.excalidraw)
  1. Low- and high-resolution leaf images are matched by filename and cropped into aligned patches with random flips and rotations.
  2. Each patch is upsampled 4x with bicubic interpolation, and the RRDB generator predicts a residual that is added on top.
  3. A hybrid loss keeps the output faithful, and a low-weight adversarial term from a conditional discriminator sharpens texture.
  4. Mixed-precision training with a cosine schedule keeps EMA-smoothed checkpoints and stops early when validation stops improving.
  5. 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/.

  1. 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
  2. Prepare the data
    python scripts/prepare_data.py plant-leaves-super-resolution-challenge.zip --out-dir data
  3. Train
    python scripts/train.py --config configs/default.yaml
  4. Enhance images

    Use scripts/make_comparison.py to 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

All projects · Home