A comprehensive machine learning project for automated classification of Retinopathy of Prematurity (ROP) in retinal images using deep learning techniques. This repository implements multiple state-of-the-art CNN architectures with advanced image preprocessing methods to achieve accurate binary classification of ROP severity.
Retinopathy of Prematurity (ROP) is a potentially blinding eye disorder that primarily affects premature infants. Early detection and accurate classification are crucial for preventing vision loss. This project develops automated classification systems to assist healthcare professionals in ROP diagnosis.
- Multiple CNN Architectures: Implementation of 6 different deep learning models
- Advanced Preprocessing: CLAHE and AMSR enhancement techniques
- Comprehensive Evaluation: Detailed performance metrics and visualizations
- Binary Classification: Normal vs Plus disease classification
- Transfer Learning: Pretrained models fine-tuned for medical imaging
| Model | Framework | Key Features |
|---|---|---|
| ResNet18 | PyTorch | Residual connections, efficient training |
| ResNet50 | PyTorch/Keras | Deeper architecture, best performance |
| VGG16 | PyTorch | Simple architecture, reliable baseline |
| VGG19 | PyTorch | Deeper VGG variant |
| DenseNet121 | PyTorch | Dense connections, parameter efficiency |
| MobileNet | TensorFlow/Keras | Lightweight, mobile-optimized |
-
CLAHE (Contrast Limited Adaptive Histogram Equalization)
- Enhances local contrast in retinal images
- Reduces noise while preserving important features
- Applied to LAB color space L-channel
-
AMSR (Automated Multi-Scale Retinex)
- Multi-scale retinex enhancement
- Brightness and contrast adjustment
- Gaussian blur filtering with multiple sigma values
-
Circular Masking
- Removes background artifacts
- Focuses on retinal region of interest
- Applied to all preprocessed images
| Model | Preprocessing | Accuracy | Sensitivity | Specificity | F1 Score | AUC |
|---|---|---|---|---|---|---|
| ResNet50 | CLAHE | 90.88% | 87.83% | 93.22% | 89.34% | 0.91 |
| DenseNet121 | CLAHE + Crop | 88.54% | 88.82% | 89.18% | 87.41% | 0.89 |
| MobileNet | CLAHE | 86.17% | 79.72% | 91.14% | 83.39% | 0.85 |
| DenseNet121 | CLAHE | 85.00% | 82.43% | 86.97% | 82.71% | 0.85 |
| ResNet18 | CLAHE + Crop | 81.47% | 75.00% | 86.45% | 77.89% | 0.81 |
| VGG16 | CLAHE | 80.88% | 79.05% | 82.29% | 78.26% | 0.81 |
| VGG19 | CLAHE | 73.23% | 96.62% | 55.20% | 75.86% | 0.76 |
ResNet50 with CLAHE preprocessing achieved the best overall performance
# Python 3.7+
# CUDA-capable GPU (recommended)# Core ML frameworks
pip install torch torchvision
pip install tensorflow keras
# Image processing
pip install opencv-python
pip install pillow
# Scientific computing
pip install numpy pandas
pip install scikit-learn
pip install matplotlib
# Additional utilities
pip install openpyxl # For Excel exportgit clone <repository-url>
cd rop-classification
pip install -r requirements.txtOrganize your dataset as follows:
dataset/
βββ 0/ # Normal cases
β βββ image1.jpg
β βββ image2.jpg
βββ 1/ # Plus disease cases
βββ image1.jpg
βββ image2.jpg
# Train ResNet50
python resnet_50_keras.py
# Train VGG19
python vgg19_torch.py
# Train DenseNet121
python densenet121_torch.py# Train MobileNet
python mobilenet.py# Apply CLAHE enhancement
from clahe import perproccessing
perproccessing('input_image.jpg', 'output_image.jpg')
# Apply AMSR enhancement
from amsr import perproccessing
perproccessing('input_image.jpg', 'output_image.jpg')Each model script automatically generates:
- Performance metrics (accuracy, sensitivity, specificity, etc.)
- Confusion matrices
- ROC curves
- Training loss plots
- Classification reports
Results are saved in model-specific directories and compiled in results.html.
βββ README.md # This file
βββ results.html # Comprehensive results comparison
βββ .gitignore # Git ignore file
β
βββ Model Implementations/
β βββ vgg16_torch.py # VGG16 PyTorch implementation
β βββ vgg19_torch.py # VGG19 PyTorch implementation
β βββ resnet_18_torch.py # ResNet18 PyTorch implementation
β βββ resnet_50_keras.py # ResNet50 Keras implementation
β βββ densenet121_torch.py # DenseNet121 PyTorch implementation
β βββ mobilenet.py # MobileNet TensorFlow implementation
β
βββ Preprocessing/
β βββ clahe.py # CLAHE enhancement
β βββ amsr.py # AMSR enhancement
β βββ mask.py # Circular masking utility
β
βββ Results/ # Experimental results
βββ resnet50 200 clahe/ # ResNet50 results
βββ densenet121 clahe 200/ # DenseNet121 results
βββ mobilenet 200 clahe/ # MobileNet results
βββ [other model results]/
- Transfer Learning: All models use ImageNet pretrained weights
- Fine-tuning: Selective layer unfreezing for medical domain adaptation
- Regularization: Dropout, batch normalization, and weight decay
- Data Augmentation: Random rotation, flipping, cropping, and color jittering
# Hyperparameters
batch_size = 32
learning_rate = 1e-4 to 1e-5
num_epochs = 200
optimizer = Adam
loss_function = CrossEntropyLoss- Accuracy: Overall classification accuracy
- Sensitivity (Recall): True positive rate
- Specificity: True negative rate
- Precision: Positive predictive value
- F1 Score: Harmonic mean of precision and recall
- Jaccard Index: Intersection over union
- AUC: Area under ROC curve
- Matthews Correlation Coefficient: Balanced metric for binary classification
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this code in your research, please cite:
@misc{rop-classification,
title={Retinopathy of Prematurity Classification using Deep Learning},
author={[NafasAmeri]},
year={2024},
howpublished={\url{https://github.com/nafasameri/ROP-Train}}
}For questions, issues, or contributions, please:
- Open an issue on GitHub
- Contact: [nafassameri@gmail.com]
This software is for research purposes only and should not be used for clinical diagnosis without proper validation and regulatory approval. Always consult qualified healthcare professionals for medical decisions.
Keywords: Retinopathy of Prematurity, Medical Image Analysis, Deep Learning, Computer Vision, Transfer Learning, PyTorch, TensorFlow, CLAHE, Medical AI