← All projects

Machine learning & biology · Retinopathy classification with a CNN

Finding disease was easier
than grading it.

Why was detecting disease easier than distinguishing its severity?

Source code on GitHub

01 / One image, two questions

Is disease present?
How severe is it?

We wanted to investigate two tasks using retinal photographs: detecting diabetic retinopathy—damage to the retina associated with diabetes—and distinguishing its severity. Using the APTOS 2019 image dataset, we trained one classifier for disease presence and another for five severity grades.

The distinction mattered. Our evaluation showed that recognising disease presence was easier than assigning its grade. To understand that gap, we examined which grades were confused and which image regions influenced the predictions.

Example labelled grade 2: original retinal photograph, Grad-CAM heatmap, overlay and focused region, from left to right.
A grade-2 example: retinal photograph, model attention heatmap, overlay and focused region. Warmer colours mark greater influence on the class score within this image. These are model responses, not manually identified lesions. Open full-size figure ↗

Binary detection

No DR / DR present

DR means diabetic retinopathy. Grade 0 is compared with grades 1–4 combined; the model outputs a probability for each of these two classes.

Severity grading

Five ordered grades

0 · No DR → 1 · Mild → 2 · Moderate → 3 · Severe → 4 · Proliferative.

Team project · Julien Le Boulch & Mélina Roge–Fakhar · Grenoble INP – Phelma · January 2026

02 / Prepare the image

Reduce variation
before learning from it.

We needed the models to learn from retinal structure despite differences in framing and illumination. We cropped black borders, standardised image size and corrected broad lighting variation. During training, transformed views exposed each model to changes in orientation and appearance.

The dataset also contained many more healthy images than severe cases. This imbalance shaped both the training objective and how we read the results: overall accuracy could hide a failure on a small class.

  1. 01

    Find the foreground

    Use grayscale intensity to locate the retinal foreground and crop the uninformative black border.

  2. 02

    Resize to 224 × 224

    Give the network a consistent input size across differently sized photographs.

  3. 03

    Correct illumination

    Subtract a blurred version of the image to reduce broad lighting variation while retaining finer structures.

  4. 04

    Augment training views

    Apply flips, rotations up to 90° and brightness, contrast and saturation perturbations during training.

The class distribution behind the training problem

Images labelled “No DR” dominate the five-class dataset. Severe cases are less frequent, so overall accuracy can hide weak performance on the less represented grades.

Training class-distribution chart: grade 0 is most frequent, followed by grade 2; grade 3 is least frequent.
Horizontal axis: severity grade; vertical axis: number of images. The distribution is dominated by grade 0, while grade 3 is least represented. For detection, grades 1–4 are combined into the disease-present class.

03 / Adapt the network

Start with visual features.
Adapt them to the retina.

We used transfer learning: start with visual features learned from a large image collection, then adapt them to the retina. Both models used EfficientNetB3, a pretrained image-classification network. We trained them separately so disease detection and severity grading each had their own learning objective.

Inside the classifier

EfficientNetB3 starts with features learned on ImageNet. After training the new output layers, we fine-tuned the full network using Adam, an optimisation algorithm, at a learning rate of 10−5.

  1. EfficientNetB3ImageNet-pretrained backbone
  2. Average poolingFeature maps → one vector
  3. Dense · 256ReLU activation
  4. Dropout · 0.5Regularization during training
  5. Softmax2 or 5 class probabilities

Phase 1 / Warmup

Freeze the backbone.

First train the new output layers to recognise our classes, keeping the existing visual feature extractor fixed.

Phase 2 / Fine-tuning

Unfreeze the network.

Then allow the visual features to adapt too, using smaller training updates to refine the network.

The training objective

Give rare grades
more influence.

We gave mistakes on underrepresented grades more weight during training, so the many healthy images would not dominate the learning objective. This encourages attention to rare classes; the confusion matrix would show whether they were actually distinguished.

Explore the calculation L=−wylog(py)

y is the true class; py is its predicted probability; wy is its class weight.

Per-image class-weighted cross-entropy: a confident wrong prediction incurs a larger penalty, scaled by the true class’s weight.

At inference: average transformed views

Test-time augmentation averages the model’s probabilities over several transformed views of an image. The idea is to reduce sensitivity to its presentation. The expression below explains the averaging rule without assuming a particular number of views.

p¯(x)=1M∑m=1Mp(Tm(x))

Tm transforms the image; M is the number of views. This describes the averaging operation; the page displays saved results and does not run a model.

04 / Understand the errors

A strong detector.
A harder grading task.

Detection classified 708 of 733 images correctly; five-class grading classified 543 of 733 correctly. Each matrix below groups those predictions by the image’s reference label (rows) and the model’s output (columns). Correct classifications lie on the diagonal.

The scores are calculated from the displayed counts. They describe these image evaluations; patient-level separation and performance on an external dataset have not been established.

Binary accuracy
96.6%
708 / 733 correct
Five-class accuracy
74.1%
543 / 733 correct
Five-class QWK
0.837
Quadratic weighted kappa · weights larger grade errors more heavily

Binary detection

True class ↓ · Predicted class →
True / pred.No DRDR present
No DR
DR present

Shade: image count, relative to the largest cell in this matrix.

12 of 372 true DR present images were predicted as No DR (3.2%).

733 images · Select or focus a cell to read it. Original matrix ↗

Five-class grading

True class ↓ · Predicted class →
True / pred.01234
0
1
2
3
4

Shade: image count, relative to the largest cell in this matrix.

20 of 39 true grade 3 images were predicted as grade 4 (51.3%).

733 images · Select or focus a cell to read it. Original matrix ↗

Severe cases expose the grading difficulty.

Only 11 of 39 grade-3 images were correctly graded; 20 were assigned grade 4. Class weighting did not remove this confusion. Switch to row percentages to compare grades independently of how many examples each contains.

Respect the order

Not all wrong grades
are equally far apart.

Quadratic weighted kappa (QWK) compares observed disagreement with the disagreement expected from the true and predicted class frequencies. Larger grade distances receive larger weights.

Explore the calculation wij=(i−j)216 κ=1−∑i,jwijOij∑i,jwijEij

O: observed counts. E: expected counts from row and column totals, Eij = ni nj / N. Here i, j ∈ {0, 1, 2, 3, 4}.

These disagreement weights are distinct from the class weights used during training.

4-grade distance → weight 1.0000 (16 × the weight of a one-grade error).

Illustrates one cell’s disagreement weight; changing grades does not change the recorded model scores.

05 / Inspect model attention

Where does the model
find its evidence?

Scores tell us which predictions were wrong, but not what drove them. We used Grad-CAM, a method that traces a class score back to influential image regions, to inspect the models’ attention. Read each example from left to right: photograph, heatmap, overlay and focused region.

Warmer colours indicate stronger influence within that map; they are not a probability of disease or a scale for comparing confidence across images. The maps suggest where to investigate a prediction, but cannot establish that the model found a lesion.

Recorded example labelled grade 2 · Moderate.

Example labelled grade 2, Moderate: retinal photograph, Grad-CAM heatmap, overlay and focused region.
Grade 2 · Moderate. Photograph → attention → overlay → focused region. Open full-size figure ↗

On small screens, swipe across the figure to inspect all four panels.

Compare the binary-model examples
Original binary Grad-CAM example labelled healthy, including original image and attention visualization.
Binary task · No DR. Open full-size figure ↗
Original binary Grad-CAM example labelled disease present, including original image and attention visualization.
Binary task · DR present. Open full-size figure ↗

06 / What comes next

Better separation.
Stronger evaluation.

The central finding was the gap between identifying disease and separating its stages. Even with class weighting, severe cases remained difficult. Improving the headline score would not be enough unless those errors also improved.

A next experiment would combine a closer examination of ambiguous grades with an evaluation that separates patients and tests images from another dataset. That would help establish whether any improvement transfers beyond this image collection.

Proposed / Hierarchical training

From presence to severity.

First learn disease presence, then adapt that representation to severity grading. This would test whether learning the broader distinction helps with finer stages. It is a proposed follow-up; the two models evaluated above were trained separately.

Proposed / Uncertainty analysis

Examine ambiguous cases.

Inspect cases where predicted probabilities are spread across several grades, then compare them with reference labels and image quality. This proposed analysis needs per-image probabilities and would test where the model is uncertain; confidence alone would not establish correctness.

These results concern image classification in a research project. Clinical usefulness would require independent evaluation; attention maps alone cannot establish it.

Explore the project’s source code

The academic foundations

Where this work connects.

Biology & biotechnologyProgramming & computational methodsSignal & image processing
Explore another projectEntrepreneurship · Gyroly ↗