Skip to content

πŸ₯ AI-powered diabetic retinopathy detection system combining ML clinical analysis with DL retinal image processing. Features ensemble models (XGBoost+RF), MobileNetV2 transfer learning, and multi-modal fusion achieving 92% accuracy. Full-stack deployment with React frontend and FastAPI backend.

License

Notifications You must be signed in to change notification settings

codedbydumi/diabetic-retinopathy-ai

Repository files navigation

πŸ₯ Diabetic Retinopathy Detection System

DR Detection Python React FastAPI TensorFlow

🌐 Live Demo: https://dr.duminduthushan.com

An AI-powered multi-modal system for diabetic retinopathy risk assessment combining clinical data analysis with retinal image processing

Website Status License Deployment


πŸ“‹ Table of Contents


πŸ” Overview

The Diabetic Retinopathy Detection System is a comprehensive healthcare AI solution that combines clinical data analysis with retinal image processing to provide accurate risk assessments for diabetic retinopathy. The system employs ensemble machine learning models and deep learning techniques to achieve high accuracy in early detection.

🎯 Key Objectives

  • Early Detection: Identify DR risk before symptoms appear
  • Multi-Modal Analysis: Combine clinical and imaging data for better accuracy
  • Accessible Healthcare: Provide rapid, automated screening
  • Clinical Decision Support: Assist healthcare providers with AI-powered insights

✨ Features

πŸ₯ Clinical Analysis

  • 13+ Clinical Parameters: Comprehensive health metrics analysis
  • Real-time Risk Assessment: Instant prediction results
  • Ensemble Models: XGBoost + Random Forest for robust predictions
  • 87.8% Accuracy: Validated on PIMA Indian Diabetes Dataset

πŸ”¬ Image Analysis

  • Retinal Image Processing: Advanced preprocessing with CLAHE
  • Transfer Learning: MobileNetV2 architecture
  • Multi-class Classification: 5-stage DR severity detection
  • Real-time Processing: Fast inference for clinical use

πŸ”„ Fusion System

  • Multi-Modal Integration: Combines clinical and image predictions
  • Weighted Risk Scoring: Intelligent risk aggregation
  • Confidence Metrics: Prediction reliability indicators
  • Feature Importance: Shows key risk factors

πŸ’» User Interface

  • Responsive Design: Works on desktop, tablet, and mobile
  • Real-time Validation: Immediate input feedback
  • Interactive Visualizations: Risk meters and progress bars
  • Professional Medical UI: Healthcare-grade interface

πŸ—οΈ Architecture

graph TB
    subgraph "Frontend - Vercel"
        A[React App] --> B[Form Validation]
        B --> C[API Client]
    end
    
    subgraph "Backend - Contabo VPS"
        D[FastAPI Server] --> E[Model Pipeline]
        E --> F[Clinical Model]
        E --> G[Image Model]
        E --> H[Fusion Model]
    end
    
    subgraph "ML Pipeline"
        I[Data Preprocessing] --> J[Feature Engineering]
        J --> K[Model Inference]
        K --> L[Risk Calculation]
    end
    
    C -->|HTTPS| D
    F --> L
    G --> L
    H --> L
    L --> M[Results]
Loading

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Python Core programming language
FastAPI REST API framework
TensorFlow Deep learning framework
Scikit-learn Machine learning library
OpenCV Image processing
NumPy Numerical computing
Pandas Data manipulation

Frontend

Technology Purpose
React UI framework
JavaScript Programming language
CSS3 Styling
Axios HTTP client

Deployment

Technology Purpose
Docker Containerization
Vercel Frontend hosting
Nginx Reverse proxy
Ubuntu Server OS

πŸš€ Installation

Prerequisites

  • Python 3.9+
  • Node.js 16+
  • Git

Clone Repository

git clone https://github.com/yourusername/diabetic-retinopathy-ai.git
cd diabetic-retinopathy-ai

Backend Setup

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Train models (optional - pre-trained models included)
python ml-pipeline/src/train_clinical_model.py
python ml-pipeline/src/train_image_model.py

# Start backend server
python backend/main.py

Frontend Setup

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start development server
npm start

Docker Setup

# Build and run with Docker Compose
docker-compose up --build

# Access application
# Frontend: http://localhost:3000
# Backend: http://localhost:8000

πŸ“Š Model Performance

Clinical Model (XGBoost Ensemble)

Metric Score
Accuracy 87.8%
Precision 84.5%
Recall 89.2%
F1-Score 86.8%
AUC-ROC 0.921

Image Model (MobileNetV2)

Metric Score
Accuracy 85.0%*
Precision 82.3%*
Recall 87.6%*
F1-Score 84.9%*
AUC-ROC 0.904*

*Note: Image model currently trained on synthetic data for demonstration. Production deployment would use APTOS 2019 or EyePACS datasets for real clinical accuracy.

Fusion Model

Metric Score
Combined Accuracy 92.0%
Clinical Weight 0.6
Image Weight 0.4

πŸ“ Project Structure

diabetic-retinopathy-ai/
β”œβ”€β”€ πŸ“‚ backend/
β”‚   β”œβ”€β”€ main.py              # FastAPI application
β”‚   β”œβ”€β”€ models.py             # Pydantic models
β”‚   β”œβ”€β”€ utils.py              # Utility functions
β”‚   └── requirements.txt      # Python dependencies
β”‚
β”œβ”€β”€ πŸ“‚ frontend/
β”‚   β”œβ”€β”€ πŸ“‚ src/
β”‚   β”‚   β”œβ”€β”€ App.js           # Main React component
β”‚   β”‚   β”œβ”€β”€ App.css          # Styles
β”‚   β”‚   └── πŸ“‚ components/   # React components
β”‚   β”œβ”€β”€ package.json         # Node dependencies
β”‚   └── public/              # Static assets
β”‚
β”œβ”€β”€ πŸ“‚ ml-pipeline/
β”‚   β”œβ”€β”€ πŸ“‚ src/
β”‚   β”‚   β”œβ”€β”€ train_clinical_model.py
β”‚   β”‚   β”œβ”€β”€ train_image_model.py
β”‚   β”‚   └── train_fusion_model.py
β”‚   β”œβ”€β”€ πŸ“‚ models/           # Trained models
β”‚   └── πŸ“‚ data/             # Training data
β”‚
β”œβ”€β”€ πŸ“‚ docker/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ docker-compose.yml
β”‚   └── nginx.conf
β”‚
└── README.md

🌐 API Documentation

Base URL

https://api.dr.duminduthushan.com

Endpoints

Health Check

GET /health

Clinical Prediction

POST /predict/clinical
Content-Type: application/json

{
  "glucose": 120,
  "blood_pressure": 70,
  "bmi": 25.5,
  "age": 35,
  ...
}

Combined Prediction

POST /predict/combined
Content-Type: multipart/form-data

Form Data:
- data: JSON clinical data
- image: Retinal image file

Model Information

GET /models/info

🚒 Deployment

The system is deployed using a distributed architecture:

  • Frontend: Vercel (Global CDN)
  • Backend: Contabo VPS (4 vCPU, 8GB RAM)
  • Domain: Cloudflare DNS
  • SSL: Let's Encrypt

Deployment Commands

# Frontend (Vercel)
vercel --prod

# Backend (VPS)
ssh user@vps-ip
cd /opt/dr-detection
docker-compose up -d

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

⚠️ Disclaimer

This system is designed for educational and research purposes only. It should not be used as a substitute for professional medical diagnosis or treatment. Always consult qualified healthcare providers for medical decisions.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ“§ Contact

Dumindu Thushan


🌟 Star this repository if you find it helpful!

πŸ” Built with ❀️ by Codedbydumi for Better Healthcare

About

πŸ₯ AI-powered diabetic retinopathy detection system combining ML clinical analysis with DL retinal image processing. Features ensemble models (XGBoost+RF), MobileNetV2 transfer learning, and multi-modal fusion achieving 92% accuracy. Full-stack deployment with React frontend and FastAPI backend.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published