A deep learning project that detects Diabetic Retinopathy from retinal fundus images using a Convolutional Neural Network (CNN).
The model is trained in PyTorch, exported to ONNX for lightweight inference, and served through a FastAPI backend with a minimal HTML frontend.
Diabetic Retinopathy (DR) is one of the leading causes of blindness worldwide.
Early detection can significantly reduce vision loss.
This project automates the detection process by classifying retinal images into different stages of DR severity.
- Model: PyTorch CNN
- Inference: ONNX Runtime
- Backend: FastAPI
- Frontend: HTML/CSS (Static, hosted via GitHub Pages)
- Deployment:
- Frontend → GitHub Pages
- Backend → Render / Hugging Face Spaces
retinopathy-ai/
│
├── backend/
│ ├── app.py # FastAPI backend serving ONNX model
│ ├── retinopathy_model.onnx # Exported model for inference
│ └── requirements.txt
│
├── frontend/
│ ├── index.html # Simple UI for image upload and prediction
│ └── images/ # Sample test images
│
├── diagnosis-of-diabetic-retinopathy-by-pytorch.ipynb # Model training notebook
└── README.md
- Dataset Loading: Retinal images are loaded and organized into train, validation, and test sets.
- Preprocessing: Normalization and resizing ensure uniform CNN input.
- Model Architecture: A CNN trained to classify DR severity stages.
- Training & Evaluation:
- Optimizer: Adam
- Loss Function: CrossEntropy
- Metrics: Accuracy
- Export:
The trained PyTorch model is exported as .pt model. - Deployment:
FastAPI backend serves predictions → HTML frontend displays results.
# Clone the repository
git clone https://github.com/Talnz007/retinopathy-ai.git
cd retinopathy-ai/backend
# Install dependencies
pip install -r requirements.txt
# Run backend
uvicorn app:app --reloadThen open frontend/index.html in your browser.
Set the API endpoint in the script to:
http://127.0.0.1:8000/predict
Hosted on GitHub Pages: https://Talnz007.github.io/retinopathy-ai
- Model Type: Custom CNN
- Framework: PyTorch
- Export Format: ONNX
- Goal: Classify retinal images into diabetic retinopathy stages
- Outcome: High validation accuracy and consistent generalization across test images.
Talha Niazi B.S. Artificial Intelligence | Tech Enthusiast | Project-Based Learner
"Ship fast. Learn faster."
This project is licensed under the MIT License feel free to fork, modify, and use it for educational or research purposes.
