An AI-powered diabetic retinopathy screening application built with Python, Streamlit, and machine learning. The application analyzes retinal fundus images and predicts one of five diabetic retinopathy severity classes from 0 to 4, then provides a severity explanation, probability breakdown, and general next-step care guidance.
The project is designed as an AI-assisted screening and educational tool, not as a medical diagnostic system.
- ๐ผ๏ธ Upload retinal fundus images for screening
- ๐ค Machine-learning-based diabetic retinopathy classification
- ๐ข Prediction across five diabetic retinopathy classes (
0โ4) - ๐ Prediction probability breakdown for all classes
- ๐ฉบ Severity and risk-level explanation
- ๐ก General next-step care guidance
- ๐ Diabetic retinopathy stage reference
- ๐งช Dataset statistics
- ๐ Hold-out test accuracy display
- ๐ผ๏ธ Support for local labeled sample images from the dataset
- ๐ Educational information about Type 1, Type 2, gestational diabetes, and prediabetes
โ ๏ธ Medical-safety messaging distinguishing screening from diagnosis- ๐ Interactive Streamlit web interface
| Class | Condition |
|---|---|
0 |
No Diabetic Retinopathy |
1 |
Mild Nonproliferative Diabetic Retinopathy |
2 |
Moderate Nonproliferative Diabetic Retinopathy |
3 |
Severe Nonproliferative Diabetic Retinopathy |
4 |
Proliferative Diabetic Retinopathy |
The application also provides a description and risk level associated with each predicted class.
The application follows this pipeline:
Retinal Fundus Image
โ
Image Preprocessing
โ
Feature Extraction
โ
Standardization
โ
Logistic Regression Model
โ
Class Probabilities
โ
Predicted DR Class (0โ4)
โ
Severity + Risk Explanation
โ
Next-Step Care Guidance
Each image is:
- Converted to RGB
- Automatically contrast-adjusted
- Center-cropped to a square
- Resized to 32 ร 32
- Normalized to the
[0, 1]range
Additional image statistics, including per-channel means and standard deviations, are included in the feature representation.
The project uses a scikit-learn pipeline consisting of:
- StandardScaler for feature standardization
- Logistic Regression for five-class classification
- Balanced class weighting to help account for class imbalance
The model produces class probabilities using predict_proba(), which are displayed in the application as a prediction-probability breakdown.
The training pipeline:
- Reads labels from
train.csv - Maps each label to its corresponding retinal-image directory
- Loads available dataset images
- Applies the same preprocessing used during prediction
- Builds the feature matrix
- Splits the data into training and hold-out test sets using an 80/20 stratified split
- Trains the Logistic Regression pipeline
- Evaluates predictions on the hold-out test set
- Saves the trained model
- Saves training metrics and the classification report
The training split uses a fixed random state of 42 for reproducibility.
The application displays the model's accuracy on the hold-out test set.
The training process also generates a classification report containing class-level evaluation metrics.
The displayed accuracy should be interpreted as an evaluation result for this particular dataset split, not as clinical diagnostic accuracy.
The project uses a labeled retinal fundus image dataset referenced through train.csv.
The expected local dataset structure is:
gaussian_filtered_images/
โโโ gaussian_filtered_images/
โโโ No_DR/
โโโ Mild/
โโโ Moderate/
โโโ Severe/
โโโ Proliferate_DR/
The large retinal-image dataset is not included in this GitHub repository.
train.csv provides the image identifiers and corresponding diagnosis labels used by the training pipeline.
The Streamlit application provides three main stages:
Upload a retinal fundus image or select a labeled sample image from the local dataset.
The trained model predicts one of the five diabetic retinopathy classes.
The application displays:
- Predicted class
- Severity level
- Risk level
- Class explanation
- Prediction probability breakdown
- General next-step care guidance
The application also provides a severity explorer and educational information about diabetes types.
- Python
- scikit-learn
- Logistic Regression
- StandardScaler
- Joblib
- NumPy
- Pandas
- Pillow
- Streamlit
Diabetic-Retinopathy-Detection/
โ
โโโ app.py # Streamlit application and user interface
โโโ retina_model.py # Preprocessing, model training, prediction, and metadata
โโโ train_model.py # Training entry point
โโโ step1.py # Dataset validation utility
โโโ train.csv # Dataset labels and image identifiers
โโโ artifacts/
โ โโโ dr_model.joblib # Trained model artifact
โ โโโ training_metrics.json # Training and evaluation metrics
โโโ .gitignore
โโโ README.md
The retinal image dataset itself is not stored in the repository.
git clone https://github.com/SurajGoyal13/Diabetic-Retinopathy-Detection.git
cd Diabetic-Retinopathy-Detection
python -m venv .venv
.venv\Scripts\activate
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Place the retinal image dataset in the expected directory:
gaussian_filtered_images/
โโโ gaussian_filtered_images/
โโโ No_DR/
โโโ Mild/
โโโ Moderate/
โโโ Severe/
โโโ Proliferate_DR/
Make sure the image filenames correspond to the identifiers in train.csv.
python train_model.py
This creates or updates:
artifacts/dr_model.joblib
artifacts/training_metrics.json
streamlit run app.py
The application will open in your browser.
- Start the Streamlit application.
- Upload a retinal fundus image or choose a local sample image.
- Run the screening.
- Review the predicted diabetic retinopathy class.
- Examine the probability breakdown.
- Read the severity and risk explanation.
- Review the general next-step care guidance.
The application also provides educational information about:
- Type 1 Diabetes
- Type 2 Diabetes
- Gestational Diabetes
- Prediabetes
This educational section is separate from the retinal-image classification model.
The retinal-image model does not determine whether a person has Type 1, Type 2, gestational diabetes, or prediabetes.
This project is an AI-assisted diabetic retinopathy screening prototype.
It does not provide a medical diagnosis and should not be used as a replacement for evaluation by a qualified healthcare professional.
A model prediction may be incorrect, and a concerning result should be confirmed through appropriate clinical examination by an eye-care professional.
The probability values shown by the model are model outputs and should not be interpreted as clinical certainty.
- The model uses engineered image features and Logistic Regression rather than a deep neural network or end-to-end retinal image model.
- Model performance depends on the training dataset and preprocessing pipeline.
- The hold-out accuracy does not establish clinical diagnostic performance.
- The project does not perform clinical validation.
- The retinal-image model does not determine a person's diabetes type.
- The application requires the retinal-image dataset locally for retraining and sample-image functionality.
- Predictions should not be used as a standalone medical decision-making tool.
- ๐ง Experiment with CNN and transfer-learning architectures
- ๐ฌ Evaluate additional image preprocessing techniques
- ๐ Add precision, recall, F1-score, and confusion-matrix visualization
- ๐งช Add cross-validation and more robust model evaluation
- ๐ผ๏ธ Improve retinal-image quality checks
- ๐ฏ Explore class-imbalance handling techniques
- ๐ Add model interpretability methods such as saliency or Grad-CAM for deep-learning models
- ๐ Compare multiple machine-learning approaches
- ๐ Deploy the application for broader demonstration
- ๐ฅ Explore clinical validation with appropriate medical datasets and expert evaluation
The goal of this project is to demonstrate the practical application of machine learning to retinal fundus image screening through an interactive Streamlit application.
The project combines:
- Image preprocessing
- Feature engineering
- Multiclass machine learning
- Model evaluation
- Probability-based prediction
- Dataset analysis
- Interactive web application development
- Medical-safety-aware result presentation
The application includes educational information and care guidance informed by:
- CDC Diabetes Basics
- National Eye Institute diabetic retinopathy guidance
- National Institute of Diabetes and Digestive and Kidney Diseases (NIDDK) diabetic eye disease information
These sources are used for educational and general guidance content within the application and do not replace professional medical advice.
Suraj Goyal
Computer Science Student ยท Python ยท AI/ML ยท Web Development ยท DSA
โญ If you find this project useful, consider starring the repository.