Diabetic Retinopathy Screening - 3-Model Ensemble + FL Defense
A lightweight, privacy-preserving DR severity classification system with an integrated Federated Learning defense mechanism. MS Thesis project.
Models Included
| Model | Parameters | Size |
|---|---|---|
| MobileNetV2 | 2.2M | ~10 MB |
| EfficientNetB0 | 4.0M | ~20 MB |
| ResNet50V2 | 24.8M | ~97 MB |
Each model is a frozen pretrained backbone + custom classifier head:
GAP Dense(256,ReLU) BN Dropout(0.5) Dense(128,ReLU) BN Dropout(0.3) Dense(64,ReLU) Dense(5,Softmax)
Classification Classes
| Class | Label | Description |
|---|---|---|
| 0 | No DR | No signs of diabetic retinopathy |
| 1 | Mild NPDR | Microaneurysms only |
| 2 | Moderate NPDR | More than microaneurysms |
| 3 | Severe NPDR | Extensive hemorrhages |
| 4 | Proliferative DR | Neovascularization |
Ensemble + Calibration
The three models are combined via probability averaging with temperature scaling (T=1.5, calibrated on the APTOS 2019 validation set to minimize negative log-likelihood).
Test accuracy: ~74% on a combined APTOS 2019 + IDRiD subsample (2,000 images).
How to Run Locally
pip install -r requirements.txt
python app.py
The Gradio app launches at http://localhost:7860 with:
- Multi-image upload with automatic fundus validation
- DR severity classification with confidence scores
- Grad-CAM explainability heatmaps
- Downloadable clinical HTML report
- FL Defense visualization section
Dataset
- APTOS 2019 Blindness Detection (3,662 images) - Kaggle
- IDRiD (516 images) - IEEE ISBI 2019
Federated Learning Defense
This repo also contains code for evaluating a lightweight FL defense against label-flipping poisoning attacks. The defense uses:
- Output-layer gradient delta extraction (325-dimensional vectors)
- Pairwise cosine similarity + K-Means clustering (k=2)
- Temporal consistency tracking with permanent blacklisting
- Combined Defense ensemble (K-Means + Public Validation + FoolsGold-style consensus)
See the training script train_ensemble_colab.py for the full pipeline.
Citation
@mastersthesis{haris2026dr,
title={A Lightweight Defense Against Label-Flipping Poisoning Attacks in Federated Learning for Diabetic Retinopathy Detection},
author={Haris},
year={2026},
school={COMSATS University Islamabad, Abbottabad Campus}
}