This project implements a machine learning-based system for the early detection of diabetic retinopathy (DR) from retinal images using EfficientNet-B0. The system is built using Flask and integrates model predictions, Grad-CAM visualizations, and a user-friendly web interface.
This project offers a comprehensive solution for detecting diabetic retinopathy from retinal images. The system uses a deep learning model, EfficientNet-B0, to predict the stage of DR and visualize the reasoning behind the predictions using Grad-CAM. The results are served through a web application built with Flask, where users can upload retinal images and view predictions.
- Model Prediction: Predicts the class of diabetic retinopathy (from class 0 to 4) based on retinal image analysis.
- Confidence Score: Displays the confidence level for each prediction.
- Grad-CAM Visualization: Offers visual explanations of the model's decision-making process.
- Web Interface: Simple interface to upload retinal images, get predictions, and view associated results.
- Database Integration: Stores prediction data including patient details, predicted labels, confidence scores, and Grad-CAM images.
Make sure you have Python 3.x installed. It is also recommended to use a virtual environment for dependency management.
-
Clone the repository:
git clone https://github.com/yourusername/diabetic-retinopathy-detection.git
-
Navigate to the project directory:
cd diabetic-retinopathy-detection
-
Set up a virtual environment:
python3 -m venv .venv
-
Activate the virtual environment:
- On Windows:
.venv\Scripts\activate
- On macOS/Linux:
source .venv/bin/activate
- On Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Set up the environment variables:
- Copy the
.env.sample
file to.env
:cp .env.sample .env
- Configure the
.env
file with the necessary values (e.g., database URI, Flask secret key).
- Copy the
-
Set up the database:
- If you are using SQLite, no further configuration is needed.
- For other databases, make sure to update the database URI in
apps/config.py
.
-
Run database migrations:
flask db upgrade
-
Start the Flask application:
flask run
-
Open the web application in your browser at
http://127.0.0.1:5000
. -
Upload a retinal image to get predictions, including the predicted class, confidence score, and Grad-CAM visualization.
The project follows the structure below:
diabetic-retinopathy-detection/
├── __pycache__/ # Python bytecode cache
├── .venv/ # Virtual environment
├── apps/ # Main application folder
│ ├── __init__.py # Application initialization
│ ├── config.py # Configuration file
│ ├── authentication/ # Authentication module
│ ├── home/ # Home module (landing page)
│ ├── image/ # Image processing module
│ ├── ml_model/ # Machine learning models (e.g., EfficientNet)
│ ├── patient/ # Patient details and management
│ ├── prediction/ # Prediction logic and results
│ ├── static/ # Static files (images, CSS, JS)
│ ├── templates/ # HTML templates
│ ├── test/ # Test-related files
├── retinal_images/ # Folder for uploading retinal images
├── .env # Environment configuration
├── env.sample # Sample environment file
├── requirements.txt # List of dependencies
├── README.md # Project documentation
└── run.py # Main entry point to start the Flask app
Contributions to the project are welcome! If you encounter any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-name
). - Make your changes and commit them (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-name
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Replace
yourusername
with your actual GitHub username. - Ensure that the
.env.sample
file contains the required configurations such asDATABASE_URL
,SECRET_KEY
, etc.