Spaces:
Configuration error
AI Diabetic Retinopathy Detection
An AI-powered application for detecting diabetic retinopathy (DR) from Optical Coherence Tomography (OCT) images using deep learning and Grad-CAM visualization.
π₯ What is Diabetic Retinopathy?
Diabetic retinopathy is a diabetes complication that affects the eyes. It's caused by damage to the blood vessels of the light-sensitive tissue at the back of the eye (retina). Early detection is crucial for preventing vision loss.
π Features
- AI Classification: Uses a pre-trained ResNet-50 model to classify OCT images as DR (Diabetic Retinopathy) or NoDR (No Diabetic Retinopathy)
- Grad-CAM Visualization: Shows which areas of the image the AI focuses on for diagnosis
- Confidence Scoring: Provides probability scores for predictions
- Image Storage: Automatically saves analyzed images with timestamps
- Web Interface: User-friendly Gradio web interface
π Requirements
- Python 3.8 or higher
- PyTorch 2.0+
- CUDA-compatible GPU (optional, for faster inference)
π οΈ Installation
Clone or download this repository
git clone <repository-url> cd Deep_Learning_for_OphthalmologistCreate a virtual environment (recommended)
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activateInstall dependencies
pip install -r requirements.txt
π― Usage
Start the application
python app.pyOpen your web browser and navigate to the URL shown in the terminal (usually
http://127.0.0.1:7860)Upload an OCT image by clicking the upload area or dragging and dropping an image file
View results:
- The AI will analyze the image and show the classification result
- A Grad-CAM heatmap will highlight areas of interest
- The prediction and confidence score will be displayed
- The analyzed image will be automatically saved to the
saved_predictionsfolder
π File Structure
Deep_Learning_for_Ophthalmologist/
βββ app.py # Main application file
βββ requirements.txt # Python dependencies
βββ resnet50_dr_classifier.pth # Pre-trained model weights
βββ README.md # This file
βββ saved_predictions/ # Folder for saved analyzed images
π¬ How It Works
- Image Preprocessing: OCT images are resized to 224x224 pixels and normalized
- AI Analysis: A ResNet-50 model processes the image to classify DR vs NoDR
- Grad-CAM: Generates a heatmap showing which image regions influenced the AI's decision
- Results: Displays classification, confidence score, and visual heatmap
π Model Information
- Architecture: ResNet-50 with modified final layer for binary classification
- Training: Pre-trained on OCT image dataset
- Classes: 2 (DR - Diabetic Retinopathy, NoDR - No Diabetic Retinopathy)
- Input: 224x224 RGB images
- Output: Binary classification with confidence scores
β οΈ Important Notes
- Medical Disclaimer: This tool is for research and educational purposes only. It should not be used for actual medical diagnosis without proper validation and clinical oversight.
- Image Quality: For best results, use high-quality OCT images with good contrast and resolution
- Model Limitations: The model's accuracy depends on the quality and characteristics of the training data
π Troubleshooting
- CUDA errors: The app runs on CPU by default. If you have GPU issues, ensure PyTorch is installed correctly
- Memory issues: Large images may cause memory problems. The app automatically resizes images to 224x224
- Model loading errors: Ensure
resnet50_dr_classifier.pthis in the same directory asapp.py
π€ Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
π License
This project is for educational and research purposes. Please ensure compliance with relevant regulations when using medical imaging data.
π References
Note: This application is designed for research and educational purposes in ophthalmology and medical AI. Always consult with qualified healthcare professionals for actual medical diagnosis and treatment decisions.