Skip to content

tansugangopadhyay/Diabetic-Retinopathy-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”¬ Diabetic Retinopathy Detection System

An advanced AI-powered web application for detecting and classifying diabetic retinopathy from retinal fundus images using deep learning.

Python PyTorch Flask License

🌟 Features

  • AI-Powered Detection: Uses ResNet-152 deep learning architecture for accurate classification
  • 5 Severity Levels: Classifies diabetic retinopathy into 5 stages (No DR, Mild, Moderate, Severe, Proliferative DR)
  • Modern Web Interface: Beautiful, responsive UI with real-time analysis
  • High Accuracy: Trained model achieves medical-grade accuracy
  • Detailed Results: Provides confidence scores, probability distributions, and medical recommendations
  • Easy to Use: Simple drag-and-drop interface for image upload

πŸ“‹ Table of Contents

πŸš€ Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • 4GB+ RAM recommended
  • CUDA-capable GPU (optional, for faster inference)

Step 1: Clone the Repository

git clone <repository-url>
cd Diabetic-Retinopathy-Detection-main

Step 2: Create Virtual Environment (Recommended)

# Windows
python -m venv venv
venv\Scripts\activate

# Linux/Mac
python3 -m venv venv
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

🧠 Model Setup

The trained model file (classifier.pt) needs to be downloaded separately due to its large size.

Download the Model

  1. Download the pre-trained ResNet-152 model from:

  2. Place the classifier.pt file in the following location:

    Diabetic-Retinopathy-Detection-main/
    └── Retinal_blindness_detection_Pytorch-master/
        └── classifier.pt
    

Verify Model Path

Ensure the model path in app.py matches your setup:

MODEL_PATH = 'Retinal_blindness_detection_Pytorch-master/classifier.pt'

πŸ’» Usage

Starting the Application

  1. Start the Backend Server:

    python app.py

    The server will start on http://localhost:5000

  2. Access the Web Interface:

    • Open your browser and navigate to: http://localhost:5000
    • Or open frontend/index.html directly in your browser

Using the Application

  1. Upload Image:

    • Click on the upload area or drag and drop a retinal fundus image
    • Supported formats: PNG, JPG, JPEG (Max 16MB)
  2. Analyze:

    • Click the "Analyze Image" button
    • Wait for the AI model to process the image
  3. View Results:

    • See the severity classification
    • Review confidence scores and probability distribution
    • Read medical recommendations

Sample Images

Test images are available in:

Retinal_blindness_detection_Pytorch-master/sampleimages/

πŸ“‘ API Documentation

Base URL

http://localhost:5000/api

Endpoints

1. Health Check

GET /api/health

Response:

{
  "status": "healthy",
  "model_loaded": true,
  "device": "cuda" | "cpu"
}

2. Predict

POST /api/predict

Request:

  • Content-Type: multipart/form-data
  • Body: file (image file)

Response:

{
  "severity_value": 0,
  "severity_class": "No DR",
  "confidence": 98.5,
  "probabilities": {
    "No DR": 98.5,
    "Mild": 1.2,
    "Moderate": 0.2,
    "Severe": 0.05,
    "Proliferative DR": 0.05
  },
  "info": {
    "level": "No DR",
    "description": "No signs of diabetic retinopathy detected.",
    "recommendation": "Continue regular eye examinations...",
    "color": "#10b981",
    "risk": "Low"
  },
  "image_data": "data:image/jpeg;base64,..."
}

3. Get Classes

GET /api/classes

Response:

{
  "classes": ["No DR", "Mild", "Moderate", "Severe", "Proliferative DR"],
  "info": [...]
}

πŸ“ Project Structure

Diabetic-Retinopathy-Detection-main/
β”œβ”€β”€ app.py                          # Flask backend server
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ README.md                       # This file
β”œβ”€β”€ LICENSE                         # License file
β”œβ”€β”€ Research Paper.pdf              # Published research paper
β”‚
β”œβ”€β”€ frontend/                       # Web frontend
β”‚   β”œβ”€β”€ index.html                  # Main HTML file
β”‚   β”œβ”€β”€ styles.css                  # Styling
β”‚   └── script.js                   # JavaScript logic
β”‚
β”œβ”€β”€ Retinal_blindness_detection_Pytorch-master/
β”‚   β”œβ”€β”€ classifier.pt               # Trained model (download separately)
β”‚   β”œβ”€β”€ model.py                    # Model architecture
β”‚   β”œβ”€β”€ blindness.py                # Original GUI application
β”‚   β”œβ”€β”€ sampleimages/               # Test images
β”‚   β”œβ”€β”€ training.ipynb              # Training notebook
β”‚   β”œβ”€β”€ inference.ipynb             # Inference notebook
β”‚   └── requirements.txt            # Original requirements
β”‚
└── uploads/                        # Temporary upload folder (auto-created)

πŸ› οΈ Technology Stack

Backend

  • Framework: Flask 2.3.3
  • Deep Learning: PyTorch 1.13.1
  • Model: ResNet-152 (pretrained and fine-tuned)
  • Image Processing: Pillow, torchvision
  • API: RESTful API with CORS support

Frontend

  • HTML5: Semantic markup
  • CSS3: Modern styling with gradients, animations, glassmorphism
  • JavaScript: Vanilla JS (no frameworks)
  • Fonts: Inter, Space Grotesk (Google Fonts)

Model Architecture

  • Base Model: ResNet-152
  • Custom Classifier:
    • Linear(2048 β†’ 512) + ReLU
    • Linear(512 β†’ 5) + LogSoftmax
  • Loss Function: Negative Log Likelihood Loss
  • Optimizer: Adam
  • Input Size: 224Γ—224 RGB images

πŸ“Š Severity Levels

Level Classification Description Risk
0 No DR No signs of diabetic retinopathy Low
1 Mild Mild non-proliferative diabetic retinopathy Low-Medium
2 Moderate Moderate non-proliferative diabetic retinopathy Medium
3 Severe Severe non-proliferative diabetic retinopathy High
4 Proliferative DR Proliferative diabetic retinopathy Critical

πŸ“„ Research Paper

This project is based on published research on diabetic retinopathy detection using deep learning. The research paper is included in the repository as Research Paper.pdf.

πŸ”§ Troubleshooting

Model Not Loading

  • Ensure classifier.pt is in the correct location
  • Check the MODEL_PATH variable in app.py
  • Verify the model file is not corrupted

CORS Errors

  • Ensure Flask-CORS is installed: pip install flask-cors
  • Check that the backend server is running

Out of Memory

  • Use CPU instead of GPU for inference
  • Reduce batch size (already set to 1 for single image inference)
  • Close other applications

Port Already in Use

  • Change the port in app.py:
    app.run(debug=True, host='0.0.0.0', port=5001)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

⚠️ Disclaimer

This tool is for educational and screening purposes only. It is not a substitute for professional medical diagnosis. Always consult with a qualified healthcare professional for medical advice and treatment.

πŸ“ License

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

πŸ‘₯ Authors

  • Original Model & Research: [Research Team]
  • Web Application: [Your Name]

πŸ™ Acknowledgments

  • ResNet architecture by Microsoft Research
  • PyTorch framework
  • Kaggle for hosting the dataset and model weights
  • Medical professionals for domain expertise

πŸ“§ Contact

For questions or support, please open an issue in the repository.


Made with ❀️ for early detection and prevention of diabetic retinopathy

About

AI-powered diabetic retinopathy detection using ResNet-152 deep learning. Web app with Flask REST API, PyTorch, real-time retinal image classification, 5-stage severity detection. Medical imaging, computer vision, transfer learning, healthcare AI, ophthalmology screening tool.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors