RetinaGuard is a production-grade, end-to-end medical research & screening platform that fuses Ensemble Deep Learning (ResNet50 + DenseNet121 + EfficientNetB3 + 4608-d Feature Fusion MLP) with Classical Digital Image Processing (DIP) (Frangi vesselness filter, Hough transform Cup-to-Disc ratio, L*a*b* exudate segmentation). It features an Adaptive Quality Gate with DIP Auto-Restoration, Grad-CAM++ visual explainability, a 0โ100 Clinical Composite Risk Engine, automated Clinical PDF Report Generation, and an interactive Next.js 14 DIP Explorer Dashboard โ all exposed via FastAPI microservices and 100% open for research.
Stage 1: "Low quality or blurry fundus scan received from clinic."
Stage 2: "Black-box deep learning model yields single label without explanation."
Stage 3: "Ophthalmologists distrust raw AI confidence percentages."
Stage 4: "No structural biomarkers (CDR, vessel density) extracted to support verdict."
Stage 5: "No automated clinical report generated for patient records."
Solution: โ
You deployed RetinaGuard. Quality restored, biomarkers calculated,
4608-d ensemble fused, Grad-CAM heatmap overlayed, PDF report generated!
- ๐ฐ Single black-box CNN architecture with high variance
- ๐ No image quality validation โ processes corrupt or out-of-focus scans
- ๐ Zero quantitative structural biomarker analysis (no CDR, no VDI)
- ๐ No explainability โ doctors receive probability without spatial heatmaps
- ๐คท Manual report synthesis required for clinical documentation
- ๐ข High GPU dependency with no CPU-bound fallback capability
- ๐ป Monolithic design with no separation between DIP & DL pipelines
- ๐ค Closed proprietary lock-in with zero inspectable code
- ๐๏ธ Static pixel processing without adaptive contrast restoration
- ๐ฐ Expensive commercial software licenses
- ๐ง Pure deep learning โ ignoring 50 years of verified DIP science |
+ ๐ง 3-Model Ensemble (ResNet50 + DenseNet121 + EfficientNetB3 + Fusion MLP)
+ ๐ก๏ธ 5-Point Quality Gate (Blur, exposure, resolution, aspect ratio, FOV)
+ ๐ง Adaptive DIP Restoration (CLAHE + Unsharp Mask + Bilateral + Gamma)
+ ๐ฌ Classical DIP Engine (Frangi vessel filter, Hough Cup-to-Disc Ratio)
+ ๐ฎ Grad-CAM++ Visual Explainability with attention heatmaps
+ ๐ Composite Clinical Risk Scoring (0โ100 scaled risk severity grade)
+ ๐ Automated PDF Clinical Report generation with diagnostic visuals
+ ๐ป Interactive Next.js 14 DIP Explorer Dashboard with live gauges
+ โก FastAPI microservices with dual ODIR & APTOS multi-label support
+ ๐ณ Docker containerized with complete local execution support
+ ๐ 100% FREE & Open Source โ complete medical research transparency |
โโโโโโโโโโโโโโโโโโโโโฆโโโโโโโโโโโโโโโโโโโโฆโโโโโโโโโโโโโโโโโโโโฆโโโโโโโโโโโโโโโโโโโโ
โ ๐ง 3-Model โ ๐ฌ Classical โ ๐ก๏ธ Adaptive โ ๐ Clinical โ
โ DL Ensemble โ DIP Biomarkers โ Quality Gate โ Risk Engine โ
โ โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฃ
โ ๐ฎ Grad-CAM++ โ ๐ PDF Clinical โ ๐ป Next.js 14 โ โก FastAPI โ
โ Heatmap Engine โ Report System โ DIP Explorer โ Microservice โ
โ โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฃ
โ ๐๏ธ Optic Disc โ ๐ฉธ Vessel โ ๐ Exudate โ ๐ณ Docker โ
โ Hough CDR โ Frangi Filter โ L*a*b* Masking โ Containerized โ
โ โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโฃ
โ ๐ฅ Multi-Task โ ๐งช PyTest โ ๐ฆ ONNX Exporterโ ๐ 100% FREE โ
โ ODIR & APTOS โ Smoke Suite โ Optimization โ Open Research โ
โโโโโโโโโโโโโโโโโโโโโฉโโโโโโโโโโโโโโโโโโโโฉโโโโโโโโโโโโโโโโโโโโฉโโโโโโโโโโโโโโโโโโโโ
๐ง Deep Learning Ensemble Engine
|
๐ฌ Classical DIP Biomarker Engine
|
๐ก๏ธ Quality Gate & DIP Restoration
|
๐ Clinical Risk Engine & PDF Reports
|
๐ฎ Grad-CAM++ Explainability Engine
|
๐ป Next.js 14 Interactive Dashboard
|
Module:
ml/dip_features.pyโ High-speed CPU feature extraction using NumPy, SciPy, and Pillow.
flowchart LR
A["๐ธ Fundus Image"] --> B["๐ข Green Channel\n+ CLAHE"]
B --> C1["๐ฉธ Frangi Hessian Filter\nScale ฯ โ {1,2,3,4}"]
B --> C2["๐๏ธ Hough Circle Detector\nDisc & Cup Boundaries"]
B --> C3["๐ CIE L*a*b* Masking\nExudate Candidate Spotting"]
C1 --> D1["๐ Vessel Density Index (VDI)\nTortuosity & A/V Ratio"]
C2 --> D2["๐ฏ Cup-to-Disc Ratio (CDR)\nDiameter Ratio"]
C3 --> D3["๐ Exudate Area Ratio\nCandidate Spot Count"]
style A fill:#020617,stroke:#00d2ff,stroke-width:2px,color:#00d2ff
style B fill:#0f172a,stroke:#64ffda,stroke-width:2px,color:#64ffda
style C1 fill:#0f172a,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style C2 fill:#0f172a,stroke:#ffd93d,stroke-width:2px,color:#ffd93d
style C3 fill:#0f172a,stroke:#f093fb,stroke-width:2px,color:#f093fb
style D1 fill:#020617,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style D2 fill:#020617,stroke:#ffd93d,stroke-width:2px,color:#ffd93d
style D3 fill:#020617,stroke:#f093fb,stroke-width:2px,color:#f093fb
| Metric | Algorithm / Formula | Clinical Significance | Normal Range |
|---|---|---|---|
| Cup-to-Disc Ratio (CDR) | $\text{CDR} = \frac{\text{Diameter}{\text{cup}}}{\text{Diameter}{\text{disc}}}$ | Primary structural indicator for Glaucoma | |
| Vessel Density Index (VDI) | $\text{VDI} = \frac{\text{Pixels}{\text{vessel}}}{\text{Pixels}{\text{FOV}}}$ | Indicates vascular drop-out or proliferative vessels in DR | |
| Vessel Tortuosity | Indicates hypertensive or diabetic retinopathy changes | ||
| Exudate Candidate Area | Thresholding in $L^a^b^$ ($L^ > 75, b^* > 20$) | Indicates vascular leakage in Diabetic Macular Edema |
Module:
ml/models.pyโ Multi-backbone feature fusion architecture.
flowchart TD
IN["๐ธ Preprocessed Retinal Image (3ร512ร512)"] --> B1["๐ด ResNet50\n(layer4 bottleneck)"]
IN --> B2["๐ข DenseNet121\n(denseblock4)"]
IN --> B3["๐ต EfficientNetB3\n(features.7)"]
B1 --> F1["2048-d Feature Vector"]
B2 --> F2["1024-d Feature Vector"]
B3 --> F3["1536-d Feature Vector"]
F1 & F2 & F3 --> CONCAT["โก Concatenation Layer\n(4608-d Fused Vector)"]
CONCAT --> MLP["๐ง Fusion MLP\n4608 โ 1024 โ 512 โ 256\n(BatchNorm + Dropout 0.4)"]
MLP --> HEAD1["๐ฅ ODIR Head (5 Classes)\nNormal ยท DR ยท Glaucoma ยท Cataract ยท AMD"]
MLP --> HEAD2["๐ APTOS Head (5 Grades)\n0: None โ 4: Proliferative"]
style IN fill:#020617,stroke:#00d2ff,stroke-width:2px,color:#00d2ff
style CONCAT fill:#0f172a,stroke:#7b2ff7,stroke-width:2px,color:#7b2ff7
style MLP fill:#0f172a,stroke:#64ffda,stroke-width:2px,color:#64ffda
style HEAD1 fill:#020617,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style HEAD2 fill:#020617,stroke:#ffd93d,stroke-width:2px,color:#ffd93d
Script:
scripts/train.pyย |ย Checkpoints Directory:models/checkpoints/(Tracked via Git LFS)
The full end-to-end training pipeline has been executed and completed across both clinical task benchmarks using EfficientNet-B3 (pretrained ImageNet backbone):
| Task / Dataset | Output Classes | Saved Checkpoint | Size | Optimization Strategies |
|---|---|---|---|---|
| APTOS 2019 | 5-Class DR Severity Grading (No DR |
models/checkpoints/aptos_best.pth |
138.7 MB | Class-balanced WeightedRandomSampler, Ben Graham + CLAHE preprocessing, Cross-Entropy Loss |
| ODIR-5K | 8-Class Multi-Label Retinal Disease Screening (N, D, G, C, A, H, M, O) | models/checkpoints/odir_best.pth |
138.7 MB | Focal Loss (handles class imbalance), Cosine Annealing LR Schedule, Test-Time Augmentation (TTA) |
# Train APTOS 2019 DR Severity Model (30 epochs)
python scripts/train.py --task aptos --epochs 30
# Train ODIR-5K Multi-Label Screening Model (30 epochs)
python scripts/train.py --task odir --epochs 30
# Train Both Benchmarks Sequentially
python scripts/train.py --task both --epochs 30Modules:
ml/quality_gate.py&ml/image_restoration.py
flowchart LR
A["๐ธ Incoming Scan"] --> B{"๐ก๏ธ 5-Point Quality Check"}
B -->|"Resolution < 100px"| FAIL["โ Rejected / Error"]
B -->|"Aspect Ratio > 2.5"| FAIL
B -->|"Blur Index Var < 15"| WARN["โ ๏ธ Needs Restoration"]
B -->|"Exposure Mean Out of Range"| WARN
B -->|"Passed All Checks"| PASS["โ
Clean Image"]
WARN --> R1["1๏ธโฃ Unsharp Masking"]
R1 --> R2["2๏ธโฃ Gamma Adjustment (ฮณ=1.2)"]
R2 --> R3["3๏ธโฃ Green Channel CLAHE"]
R3 --> R4["4๏ธโฃ Bilateral Filter"]
R4 --> PASS
PASS --> OUT["๐ Send to DL & DIP Engines"]
style A fill:#020617,stroke:#00d2ff,stroke-width:2px,color:#00d2ff
style B fill:#0f172a,stroke:#ffd93d,stroke-width:2px,color:#ffd93d
style WARN fill:#0f172a,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style PASS fill:#020617,stroke:#64ffda,stroke-width:2px,color:#64ffda
Modules:
ml/risk_score.py&ml/pdf_report.py
flowchart TD
DL_CONF["๐ง DL Max Confidence"] --> SCORE["๐ Composite Risk Engine\nWeighted Aggregator"]
VDI["๐ฉธ Vessel Density %"] --> SCORE
CDR["๐๏ธ Cup-to-Disc Ratio"] --> SCORE
EXUDATE["๐ Exudate Spot Area"] --> SCORE
QUALITY["๐ก๏ธ Quality Gate Flag"] --> SCORE
SCORE --> NUM["๐ข Composite Risk Score (0โ100)"]
NUM --> S1["0โ15: Low Risk (Normal)"]
NUM --> S2["16โ35: Moderate Risk (Mild)"]
NUM --> S3["36โ55: Elevated Risk (Moderate)"]
NUM --> S4["56โ75: High Risk (Severe)"]
NUM --> S5["76โ100: Critical Risk (Proliferative)"]
NUM --> PDF["๐ Generate PDF Clinical Report\n(HTML + WeasyPrint / ReportLab)"]
style SCORE fill:#0f172a,stroke:#7b2ff7,stroke-width:2px,color:#7b2ff7
style NUM fill:#020617,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style PDF fill:#020617,stroke:#64ffda,stroke-width:2px,color:#64ffda
flowchart TD
subgraph CLIENT["๐ฅ๏ธ CLIENT TIER โ Next.js 14 + React 18"]
U["๐ค Clinician / Researcher"] --> FE["โก App Router Workspace"]
FE --> DASH["๐ Dashboard & Analytics"]
FE --> INTAKE["๐ Patient Demographics Form"]
FE --> DIP_VIS["๐ฌ DIP Explorer (5 Visual Tabs)"]
FE --> HEATMAP["๐ฎ Grad-CAM Attention View"]
FE --> REPORT["๐ PDF Report Downloader"]
end
subgraph API["โก API TIER โ FastAPI Microservices"]
GW["๐ REST API Gateway\n(backend/app/main.py)"] --> PREDICT["POST /predict"]
GW --> HEAT_ENDPOINT["POST /generate-heatmap"]
GW --> REP_ENDPOINT["POST /generate-report"]
GW --> DIP_ENDPOINT["POST /dip-analysis"]
GW --> RESTORE_ENDPOINT["POST /restore"]
GW --> RISK_ENDPOINT["POST /risk-score"]
end
subgraph ENGINE["๐ง CORE ENGINE TIER โ PyTorch + OpenCV"]
QG["๐ก๏ธ Quality Gate & Restorer"]
DL["๐ง DL Ensemble (ResNet+DenseNet+EfficientNet)"]
DIP["๐ฌ DIP Biomarker Pipeline"]
CAM["๐ฎ Grad-CAM++ Generator"]
RISK["๐ Composite Risk Engine"]
PDF_ENG["๐ Clinical PDF Synthesizer"]
end
PREDICT --> QG --> DL & DIP --> RISK --> GW
HEAT_ENDPOINT --> CAM --> GW
REP_ENDPOINT --> PDF_ENG --> GW
DIP_ENDPOINT --> DIP --> GW
RESTORE_ENDPOINT --> QG --> GW
RISK_ENDPOINT --> RISK --> GW
style CLIENT fill:#020617,stroke:#00d2ff,stroke-width:2px,color:#00d2ff
style API fill:#0f172a,stroke:#7b2ff7,stroke-width:2px,color:#7b2ff7
style ENGINE fill:#0f172a,stroke:#64ffda,stroke-width:2px,color:#64ffda
flowchart LR
A["๐ธ Upload Image\n+ Demographics"] --> B["๐ก๏ธ Quality Gate Check"]
B -->|"Low Quality"| C["๐ง DIP Restoration\nCLAHE + Unsharp"]
B -->|"High Quality"| D["โก Parallel Execution"]
C --> D
D --> E1["๐ง 4608-d DL Ensemble\nPathology Inference"]
D --> E2["๐ฌ Classical DIP Engine\nCDR + VDI + Exudates"]
E1 & E2 --> F["๐ Composite Risk Scoring\n0โ100 Grade"]
F --> G["๐ฎ Grad-CAM++ Heatmap\nLesion Attention Map"]
G --> H["๐ PDF Clinical Report\nDownloadable PDF"]
style A fill:#020617,stroke:#00d2ff,stroke-width:2px,color:#00d2ff
style B fill:#0f172a,stroke:#ffd93d,stroke-width:2px,color:#ffd93d
style D fill:#0f172a,stroke:#7b2ff7,stroke-width:2px,color:#7b2ff7
style F fill:#0f172a,stroke:#ff6b6b,stroke-width:2px,color:#ff6b6b
style H fill:#020617,stroke:#64ffda,stroke-width:2px,color:#64ffda
๐ Backend & ML Frameworks
๐ฅ๏ธ Frontend Dashboard
๐ณ Infrastructure & DevOps
| Technology | Role |
|---|---|
| Multi-stage containerized deployment | |
| ๐ฆ ONNX Runtime | High-speed optimized model deployment format |
| ๐งช PyTest | Automated test suite & smoke test verification |
RetinaGuard/
โโโ ๐ง backend/
โ โโโ app/
โ โโโ main.py # FastAPI REST server โ 8 endpoints
โ โโโ __init__.py
โ
โโโ ๐จ frontend/
โ โโโ src/
โ โโโ app/ # Next.js 14 App Router
โ โ โโโ layout.tsx # Root HTML wrapper & fonts
โ โ โโโ page.tsx # Main screening workspace page
โ โโโ components/
โ โโโ DIPExplorer.tsx # 5-tab DIP visualizer & animated gauges
โ โโโ AnalysisWorkspace.tsx # File uploader & diagnostic layout
โ โโโ PatientIntakeForm.tsx # Clinical demographics entry
โ โโโ HeroSection.tsx # Animated landing hero banner
โ โโโ EnsemblePipeline.tsx # DL architecture diagram
โ โโโ ResearchMetrics.tsx # SOTA performance counters
โ โโโ DiseaseReference.tsx # Pathology classification guide
โ โโโ SiteHeader.tsx # Top navigation header
โ โโโ SiteFooter.tsx # Footer & clinical disclaimer
โ โโโ TickerBar.tsx # Live metric ticker
โ
โโโ ๐ง ml/ # Core ML & DIP Algorithms
โ โโโ models.py # ResNet50 + DenseNet121 + EfficientNetB3 + Fusion MLP
โ โโโ inference.py # Inference engine with CPU/GPU dispatch
โ โโโ gradcam.py # Grad-CAM++ visual explainability engine
โ โโโ dip_features.py # Classical DIP biomarkers (Frangi, CDR, Exudates)
โ โโโ image_restoration.py # Adaptive quality gate & restoration pipeline
โ โโโ quality_gate.py # 5-point quality inspection engine
โ โโโ risk_score.py # 0โ100 Composite clinical risk engine
โ โโโ pdf_report.py # Automated clinical PDF report generator
โ โโโ preprocessing.py # Retinal image preprocessor (CLAHE, cropping)
โ โโโ schemas.py # Pydantic data schemas
โ โโโ training.py # Training & validation loops
โ โโโ dataset_adapters.py # ODIR & APTOS dataset loaders
โ โโโ data_validation.py # Dataset integrity verification
โ โโโ onnx_exporter.py # ONNX model compilation utility
โโโ ๐ฆ models/ # Model Checkpoints (Git LFS)
โ โโโ checkpoints/
โ โโโ aptos_best.pth # Trained 5-Class DR Severity Model (138.7 MB)
โ โโโ odir_best.pth # Trained 8-Class Multi-Label Model (138.7 MB)
โ
โโโ ๐ .github/assets/ # Animated SVG badges & graphics
โโโ ๐ configs/ # YAML dataset & model configurations
โโโ ๐ scripts/ # train.py ยท generate_fixtures.py ยท smoke_test.py
โโโ ๐ tests/ # PyTest automated unit & integration tests
โโโ ๐ docs/ # PROJECT_COMPLETE_DOCUMENTATION.md
โโโ ๐ณ docker-compose.yml # Docker multi-container orchestrator
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ README.md # Project documentation
Base URL:
http://localhost:8000ย |ย Swagger Docs:http://localhost:8000/docs
| Method | Endpoint | Description | Key Parameters / Payload |
|---|---|---|---|
GET |
/health |
System status & supported tasks | โ |
GET |
/metadata |
Architecture & dataset configuration | โ |
POST |
/predict |
Full pipeline inference (DL + DIP + Risk) | file (Multipart Image), task (odir/aptos), Patient metadata |
POST |
/generate-heatmap |
Grad-CAM++ visual explainability map | file (Image), target_class |
POST |
/generate-report |
Complete clinical HTML/PDF report | file (Image), Patient metadata |
POST |
/dip-analysis |
DIP biomarker extraction only | file (Image) |
POST |
/restore |
Quality inspection & DIP restoration | file (Image) |
POST |
/risk-score |
Composite clinical risk score calculation | file (Image) |
๐ Sample Request & Response Payload โ POST /predict (Click to expand)
{
"request_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"task": "odir",
"top_prediction": "Diabetic Retinopathy",
"calibrated_confidence": 0.874,
"class_probabilities": {
"Normal": 0.082,
"Diabetic Retinopathy": 0.874,
"Glaucoma": 0.028,
"Cataract": 0.009,
"AMD": 0.007
},
"quality_gate": {
"passed": true,
"checks": {
"resolution": true,
"aspect_ratio": true,
"blur_index": true,
"exposure": true,
"fov_coverage": true
}
},
"dip_biomarkers": {
"vessel_density_index": 0.142,
"cup_to_disc_ratio": 0.42,
"optic_disc_found": true,
"exudate_candidate_count": 7,
"exudate_area_ratio": 0.023,
"vessel_tortuosity_index": 0.11
},
"clinical_risk": {
"composite_risk_score": 62.4,
"severity_grade": "Severe NPDR",
"risk_level": "High Risk"
}
}git clone https://github.com/Jawahar08/RetinaGuard.git
cd RetinaGuard
git checkout shrirampip install -r requirements.txtpython scripts/generate_fixtures.py # Create synthetic retinal images
python scripts/smoke_test.py # Execute end-to-end CPU verificationpython -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000๐ก Server live at: http://127.0.0.1:8000 ย |ย ๐ Docs: http://127.0.0.1:8000/docs
cd frontend
npm install
npm run dev๐ฅ๏ธ Dashboard live at: http://localhost:3000
Run both backend microservice and frontend web app with a single command:
docker-compose up --build| Service | Port | Description |
|---|---|---|
backend |
:8000 |
FastAPI service (PyTorch + OpenCV + DIP Engine) |
frontend |
:3000 |
Next.js 14 Dashboard UI |
Non-Clinical Research & Educational System RetinaGuard is designed strictly for research, software architecture demonstration, and educational purposes. It is not an FDA-cleared, CE-marked, or clinically certified medical device. All outputs, risk scores, and visual heatmaps must be verified by a licensed ophthalmologist or healthcare professional before any diagnostic or clinical decision.
RetinaGuard ยฉ 2026 โ Research & Educational Use Only ยท Made with CJโค๏ธ