Skip to content

Latest commit

ย 

History

98 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RetinaGuard โ€” AI-Powered Retinal Fundus Screening Platform

Model Training Python 3.10+ PyTorch 2.0+ FastAPI Next.js 14 OpenCV Git LFS License Research System PRs Welcome Stars Docker Ready


Platform Stats

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.


Feature Overview
RetinaGuard Workspace Dashboard



๐Ÿ’ก The Problem

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!

โŒ Traditional Ocular AI Tools

- ๐Ÿ˜ฐ 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

โœ… RetinaGuard AI System

+ ๐Ÿง  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


โœจ Features at a Glance

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฆโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฆโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฆโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘   ๐Ÿง  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

4608-dimensional feature concatenation

  • โœ… ResNet50 (2048-d layer4 bottleneck features)
  • โœ… DenseNet121 (1024-d denseblock4 features)
  • โœ… EfficientNetB3 (1536-d top feature maps)
  • โœ… FeatureFusionRetinalModel โ€” concatenates 4608-d vectors into a 4-layer MLP classifier
  • โœ… Multi-task support: ODIR (5-class multi-label) & APTOS (5-grade DR severity)
  • โœ… CPU fallback execution mode when CUDA is unavailable

๐Ÿ”ฌ Classical DIP Biomarker Engine

Pure CPU mathematical feature extraction

  • โœ… Frangi Vessel Filter: Multi-scale Hessian matrix ($\sigma \in {1,2,3,4}$) for Vessel Density Index (VDI)
  • โœ… Optic Disc & Cup Detection: Circular Hough Transform for Cup-to-Disc Ratio (CDR)
  • โœ… Exudate Segmentation: CIE L*a*b* + HSV color space thresholding
  • โœ… Vessel Tortuosity & A/V Ratio: Arteriole-to-venule ratio & arc length curvature metrics
  • โœ… Microaneurysm candidate spot detection

๐Ÿ›ก๏ธ Quality Gate & DIP Restoration

Pre-inference image validation and enhancement

  • โœ… 5-Point Check: Resolution, aspect ratio, blur index ($\text{Var}(\nabla^2 I)$), exposure mean ($\mu$), FOV coverage
  • โœ… Auto-Restoration Pipeline:
    1. Unsharp masking for crisp vessel boundaries
    2. Gamma correction ($\gamma = 1.2$) for dark region enhancement
    3. CLAHE (Contrast Limited Adaptive Histogram Equalization)
    4. Bilateral filtering for noise reduction while preserving edges

๐Ÿ“Š Clinical Risk Engine & PDF Reports

Automated patient risk stratification & documentation

  • โœ… Composite Risk Score (0โ€“100): Integrates DL class probabilities, VDI, CDR, exudate area, and quality flags
  • โœ… 5-Tier Severity Scale: Normal โ†’ Mild โ†’ Moderate โ†’ Severe โ†’ Critical
  • โœ… Automated PDF Generation: Formatted HTML/PDF export with patient demographics, biomarker tables, and diagnostic overlays
  • โœ… Auto-generated clinical recommendations

๐Ÿ”ฎ Grad-CAM++ Explainability Engine

Spatial visual attention heatmaps

  • โœ… Grad-CAM++ Implementation: Second-order derivative weighting for multi-instance lesion localization
  • โœ… Overlay Generation: Jet colormap alpha-blended ($\alpha = 0.45$) onto fundus images
  • โœ… Target Class Selection: Inspect heatmaps for any target pathology (DR, Glaucoma, AMD, Cataract, Normal)
  • โœ… Base64 PNG export for dashboard rendering

๐Ÿ’ป Next.js 14 Interactive Dashboard

Modern visual inspection workspace

  • โœ… Multi-tab DIP Explorer: Original, Restored, Vessels, Optic Disc, Grad-CAM
  • โœ… Animated circular SVG metric gauges (CDR, VDI, Risk, Confidence)
  • โœ… Patient intake form with diabetic & hypertension clinical metadata
  • โœ… Real-time FastAPI backend integration
  • โœ… Built with React 18, TypeScript, Tailwind CSS, and Lucide React


๐Ÿ”ฌ Feature 1 โ€” Classical DIP Biomarker Extraction

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
Loading

Extracted Biomarkers Summary

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 $< 0.55$
Vessel Density Index (VDI) $\text{VDI} = \frac{\text{Pixels}{\text{vessel}}}{\text{Pixels}{\text{FOV}}}$ Indicates vascular drop-out or proliferative vessels in DR $10% - 18%$
Vessel Tortuosity $\tau = \frac{\text{Arc Length}}{\text{Chord Length}} - 1$ Indicates hypertensive or diabetic retinopathy changes $< 0.15$
Exudate Candidate Area Thresholding in $L^a^b^$ ($L^ > 75, b^* > 20$) Indicates vascular leakage in Diabetic Macular Edema $0.0%$


๐Ÿง  Feature 2 โ€” Deep Learning Ensemble Engine

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
Loading

๐Ÿ† Model Training & Checkpoint Milestone (Completed)

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 $\rightarrow$ Proliferative 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)

Execute Training Pipeline

# 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 30


๐Ÿ›ก๏ธ Feature 3 โ€” Adaptive Quality Gate & Image Restoration

Modules: 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
Loading


๐Ÿ“Š Feature 4 โ€” Clinical Risk Engine & PDF Reports

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
Loading


๐Ÿ—๏ธ System Architecture

High-Level Overview

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
Loading


๐Ÿ”„ Core Product Flow

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
Loading


๐Ÿ› ๏ธ Tech Stack

Tech Stack
๐Ÿ Backend & ML Frameworks
Technology Role Version
Python Core runtime environment 3.10+
PyTorch Deep learning model inference & feature extraction 2.0+
FastAPI High-performance asynchronous REST API backend 0.100+
OpenCV Classical digital image processing & matrix ops 4.7+
๐Ÿ”ข NumPy / SciPy Matrix math, Frangi Hessian filters, signal processing latest
๐Ÿงช scikit-image Morphological filtering, watershed segmentation, CLAHE latest
๐Ÿ“‹ Pydantic Strict API data validation & request/response schemas 2.0+
๐Ÿ–ฅ๏ธ Frontend Dashboard
Technology Role Version
Next.js React application framework (App Router) 14
React Component UI rendering engine 18
TypeScript Type-safe development 5
Tailwind CSS Custom styling & glassmorphic layout 3.x
๐Ÿ’Ž Lucide React Icon library for clinical UI elements latest
๐Ÿณ Infrastructure & DevOps
Technology Role
Docker Multi-stage containerized deployment
๐Ÿ“ฆ ONNX Runtime High-speed optimized model deployment format
๐Ÿงช PyTest Automated test suite & smoke test verification


๐Ÿ“ Project Structure

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


๐Ÿ“ก API Reference

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"
  }
}


๐Ÿš€ Quick Start

1๏ธโƒฃ Clone & Switch Branch

git clone https://github.com/Jawahar08/RetinaGuard.git
cd RetinaGuard
git checkout shriram

2๏ธโƒฃ Install Python Dependencies

pip install -r requirements.txt

3๏ธโƒฃ Generate Test Fixtures & Run Smoke Test

python scripts/generate_fixtures.py       # Create synthetic retinal images
python scripts/smoke_test.py              # Execute end-to-end CPU verification

4๏ธโƒฃ Start FastAPI Backend

python -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

5๏ธโƒฃ Start Next.js Frontend

cd frontend
npm install
npm run dev

๐Ÿ–ฅ๏ธ Dashboard live at: http://localhost:3000



๐Ÿณ Docker Deployment

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


โš ๏ธ Medical & Research Disclaimer

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.



Built with PyTorch ยท FastAPI ยท Next.js 14 ยท OpenCV ยท Classical DIP ยท Grad-CAM++
RetinaGuard ยฉ 2026 โ€” Research & Educational Use Only ยท Made with CJโค๏ธ

About

Ensemble Deep Learning for Retinal Disease Detection and Classification with Explainable AI.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages