
Diabetic Retinopathy Grading — Retinal AI Model
Diabetic-retinopathy grading built to test generalisation across datasets, cameras and sites — calibrated, with an abstain-and-refer option.
- ConvNeXt-Tiny, 512 px
- 32,215
- Frozen before results
What it had to solve
Retinal datasets differ in camera, resolution, population and grading practice, and a network will happily learn those differences instead of the disease. In APTOS and DeepDRiD, grade-0 images come from a different camera than the rest, so image size alone predicts the label. Public sets also contain the same images under different names, which silently leaks test data into training. And a grade on its own is not enough in a screening setting: the model has to know when it is unsure and refer the image to a person.
The decisions that shaped it
The protocol before the results
The evaluation protocol was frozen on 26 October 2026, and every later change went into its deviations log. Locked test sets are used once, at the end, and every read of locked labels is recorded in an access log. Design choices, thresholds and early stopping use development data only.
Data engineering as a gate
Images were deduplicated across datasets by exact and perceptual hash; any locked-set image that also appeared in training was removed from training, never from the locked set. Of 50,763 images, 32,215 trained the model, 519 were excluded with a recorded reason, and locked labels were never edited or cleaned.
Testing for shortcuts first
Before any real model, a shortcut-only baseline was trained on image size, brightness, border statistics and source dataset. If it scored well, dataset artefacts mattered. That check is what surfaced the grade-0 camera difference, and it shaped the data mix the real model was trained on.
Calibrated, with abstain-and-refer
Probabilities are calibrated by temperature scaling and checked with reliability plots. An optional development-fixed rule flags the ambiguous 7 to 30% of positive calls for human review without changing sensitivity, and concentrates errors: on Messidor-2 the referable error rate is 0.595 among flagged images and 0.088 among the rest.
Reported as it came out
Ninety-five per cent intervals come from a patient-level bootstrap with 2,000 resamples, subgroups too small to conclude are marked so, and the weak cases are stated: mild-DR recall, and ultra-widefield cameras, which are out of scope. Two exploratory versions are reported separately because the locked sets had already been seen.
How the pieces sit together
- EyePACS, APTOS, DDR, IDRiD, Messidor-2 and more; manifests, licences and quality gates
- Exact and perceptual hashing across datasets; overlaps removed from training only
- Predicted image quality per dataset, ungradable handling, incident log
- ConvNeXt-Tiny at 512 px via timm, three seeds; DINOv2 features as an ablation
- Temperature scaling, reliability plots, coverage against accuracy
- Macro QWK and referable AUROC over locked sets, patient-level bootstrap intervals
- Fixed seeds, config hash and git commit per run, pinned environment, DVC
Built into the product
Five grades and referable DR
The full 0–4 scale and the clinically used referable threshold, with ungradable images counted as referable.
Locked-set discipline
Four external sets scored once, with every access to their labels logged.
Shortcut audit
A model trained only on image artefacts, to measure how much a dataset gives away.
Abstain and refer
A development-fixed rule that hands the most ambiguous positives to a person.
Model card
Intended use, operating points and limitations written down before any claim is made.
56 automated tests
Metrics, caching, deduplication and splits, locked-set access, evaluation and a training smoke test.
What it is built out of
- PyTorch, timm, ConvNeXt, DINOv2
- Perceptual hashing, DVC, Manifests
- Quadratic weighted kappa, AUROC, Bootstrap intervals, Temperature scaling
- Python 3.11, CUDA 12.8, pytest
What it looks like





What it produced
- 0.792
- Macro QWK on the locked sets (v1 headline)
- 0.595 vs 0.088
- Error rate, flagged vs unflagged (Messidor-2)
- 56
- Automated tests