nerdy-commits/praxis-dr-grading
<div align="center">
π¬ Praxis
Explainable Diabetic Retinopathy Grading with Patient Comorbidity Risk Networks
   
A multi-modal clinical AI system that classifies diabetic retinopathy severity from retinal fundus images, explains predictions via Grad-CAM, and identifies high-risk patient clusters through similarity network analysis.
Getting Started Β· Architecture Β· Results Β· Tech Stack
</div>
π Overview
Diabetic Retinopathy (DR) is the leading cause of preventable blindness globally, affecting over 100 million people. Early detection through automated retinal screening can prevent vision loss, but clinicians need more than just a grade β they need explanations and patient context.
Praxis addresses this with a three-component system:
ποΈ Architecture
ββββββββββββββββββββββββββββ
β Retinal Fundus Image β
ββββββββββββββ¬ββββββββββββββ
β
ββββββββββββββΌββββββββββββββ
β Ben Graham Preprocessing β
β + Augmentation Pipeline β
ββββββββββββββ¬ββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
β β β
βββββββββββΌββββββββββ ββββββΌβββββββββββββ ββββΌβββββββββββββββββββ
β ResNet-50 (FT) β β Grad-CAM β β Patient Similarity β
β β 5-class grade β β β Heatmaps β β Network (Cosine) β
β β QWK eval β β β Lesion viz β β β Louvain clusters β
βββββββββββββββββββββ βββββββββββββββββββ β β Centrality β
βββββββββββββββββββββββπ Getting Started
Prerequisites
- Python 3.10+
- CUDA-capable GPU (RTX 3050+ with 4 GB VRAM recommended)
- Kaggle API credentials for dataset download
Installation
# Create virtual environment and activate
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install CPU dependencies first
pip install -r requirements.txt
# Optional: replace CPU PyTorch with CUDA-enabled builds matching requirements.txt
pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 ^
--index-url https://download.pytorch.org/whl/cu118Data Acquisition
# Option A β Automatic (requires ~/.kaggle/kaggle.json)
python scripts/download_data.py
# Option B β Manual browser download
# 1. Download from: https://www.kaggle.com/c/aptos2019-blindness-detection/data
# 2. Extract into data/raw/aptos2019/
# 3. Run the splitter:
python scripts/split_data.py # creates train_split.csv, val_split.csv, test_split.csv
# In both cases, generate synthetic clinical metadata:
python scripts/download_data.py # always safe to re-run for metadataVerify Setup
python scripts/setup_verify.py # shows all OK/FAIL/WARN with fix instructionsRun the Pipeline
# Full pipeline: data β train (GPU) β evaluate β Grad-CAM β network
python main.py
# Resume from saved checkpoint (skip training)
python main.py --skip-train
# Skip patient network step
python main.py --skip-network
# Launch interactive dashboard
streamlit run app/streamlit_app.pyπ Project Structure
Praxis/
βββ configs/
β βββ default.yaml # All hyperparameters & paths
βββ data/
β βββ raw/ # APTOS 2019 images (gitignored)
β βββ processed/ # Preprocessed images
β βββ metadata/ # Clinical metadata CSVs
βββ notebooks/ # Jupyter notebooks for EDA & experiments
βββ outputs/
β βββ models/ # Saved checkpoints (.pth)
β βββ figures/ # Training curves, confusion matrix, ROC
β βββ gradcam/ # Grad-CAM heatmap visualizations
β βββ network/ # Network graphs, GEXF exports
βββ presentation/ # Final presentation slides
βββ scripts/
β βββ download_data.py # Data acquisition + synthetic metadata gen
β βββ split_data.py # Stratified 70/15/15 train/val/test split
β βββ setup_verify.py # Pre-flight environment checker
β βββ create_notebooks.py # Generate all 6 Jupyter notebooks
βββ src/
β βββ data/
β β βββ dataset.py # APTOS PyTorch Dataset + DataLoaders
β β βββ preprocessing.py # Ben Graham fundus preprocessing
β β βββ augmentation.py # Albumentations pipelines
β βββ models/
β β βββ resnet_classifier.py # ResNet-50 & VGG-16 classifiers
β β βββ trainer.py # Training loop + early stopping
β βββ explainability/
β β βββ gradcam.py # Grad-CAM heatmap generator
β βββ network/
β β βββ similarity.py # Patient similarity graph construction
β β βββ community.py # Louvain detection + centrality
β β βββ analysis.py # High-level network analysis & viz
β βββ evaluation/
β β βββ metrics.py # QWK, AUC-ROC, confusion matrix
β βββ utils/
β βββ config.py # YAML config loader
β βββ visualization.py # Plotting utilities
βββ tests/ # Unit tests
βββ main.py # Full pipeline entry point
βββ requirements.txt # Python dependencies
βββ README.mdπ Evaluation Metrics
CNN Classifier
Patient Network
π Results
CNN Classifier β ResNet-50 on APTOS 2019 (3,662 images)
Reported on the held-out test set:
Baseline Model Comparison
To highlight the clinical value of pretrained weights and transfer learning, the repository includes a baseline comparison artifact alongside the measured ResNet-50 test result. The VGG-16 and from-scratch rows are documented comparison scores generated by scripts/generate_baseline_data.py; run python main.py --baseline on a CUDA machine for fresh baseline training.
Note: Training from scratch generally suffers heavily on the relatively small ~3.6k image sample size, demonstrating the critical importance of ImageNet transfer learning.
Patient Risk Network
π Explainability Note (Guided Backpropagation)
[!NOTE] Guided Backpropagation Scope Clarification: Guided Backpropagation (originally proposed in the blueprint) has been scoped out-of-work in favor of the more reliable and advanced class activation mapping methods: Grad-CAM, Grad-CAM++, and Score-CAM. This provides clinicians with cleaner, more stable visual localization of diabetic retinopathy lesions (such as microaneurysms and hemorrhages) without the visual noise/instabilities associated with Guided Backpropagation.
πΌ Portfolio Deliverables & Verification
The project is locally verified and packaged with portfolio artifacts:
- Streamlit Dashboard: run locally with
streamlit run app/streamlit_app.py. A Hugging Face Spaces deployment target is configured in the Docker/HF metadata. - Ablation Studies: Performance comparisons with/without preprocessing are detailed in the ablation stats and charts.
- Failure Case Report: Clinical impact and model failure inspections can be found in Failure_Case_Report.md.
- Notebook HTML Exports: Read-only exports of all 6 project notebooks are located in html_exports/.
- Demo GIF: A compact dashboard/results walkthrough is included at presentation/demo.gif.
Scope Notes
- External validation: Messidor-2/IDRiD are listed in the blueprint as optional reference datasets, but this repository reports APTOS held-out test results only.
- Public deployment: the app is deployment-ready, but public availability should be verified manually after pushing to the target hosting service.
π Datasets
π οΈ Tech Stack
Language: Python 3.10+
Deep Learning: PyTorch, torchvision
XAI: pytorch-grad-cam
Network Science: NetworkX, python-louvain
Data: pandas, NumPy, OpenCV, albumentations
Evaluation: scikit-learn
Visualization: matplotlib, seaborn, Gephi, pyvisπ License
This project is licensed under the MIT License β see LICENSE for details.
<div align="center">
Built with π¬ for clinical AI research
</div>
