Diabetic Retinopathy Detection with EfficientNet

November 2024 Medical ai Academic Project Ibn Tofail University, Kenitra October 2024 - December 2024
Diabetic Retinopathy Detection with EfficientNet
Medical AI EfficientNet Deep Learning Computer Vision Healthcare Classification Transfer Learning

🎯 Project Overview

Deep Learning system for automatic detection and classification of diabetic retinopathy from retinal images. The model uses EfficientNetB0 to classify images into 5 severity stages, enabling early detection and automated disease monitoring.

Team:

  • Abdelrhafour EL MOUSSAOUI
  • Mouad AOUTIR
  • El Mehdi HICHAM
  • Mohammed Imrane GRICH

Supervised by: Pr. Souad EDDAROUICH

Key Achievement: 97% accuracy on validation set with a lightweight and efficient model.


🔍 Problem Statement

Medical Context

Diabetic retinopathy is one of the most common complications of diabetes and a major cause of blindness worldwide. Early detection is essential to limit the risk of vision loss.

Challenges

  • 🏥 Manual diagnosis: Slow and subjective, requires expert ophthalmologists
  • 📈 Growing volume: Increase in diabetes cases worldwide
  • 🎯 Subtle signs: Difficult to detect early stages
  • 💰 High cost: Regular examinations are expensive and time-consuming
  • 🌍 Limited access: Lack of specialists in rural areas

Solution

Deep Learning model based on EfficientNetB0 for:

  • Automatic classification into 5 stages
  • Early and objective detection
  • Automated progression monitoring
  • Improved diagnostic accessibility

🏗️ Dataset: APTOS 2019

Description

Source: Kaggle Competition - APTOS 2019 Blindness Detection
Volume: 3,662 high-resolution retinal images
Annotation: Expert ophthalmologists

Classes (5 Stages)

Class Label Description Distribution
No_DR (0) Absent Normal retina, no abnormality ~45%
Mild (1) Mild Microaneurysms, mild hemorrhages ~15%
Moderate (2) Moderate Evident vascular abnormalities ~20%
Severe (3) Severe Abundant hemorrhages, edema ~12%
Proliferate_DR (4) Proliferative Neovascularization, risk of blindness ~8%

🔧 Preprocessing Pipeline

Image Processing

Step 1: Gaussian Filtering

  • Visual noise reduction
  • Preservation of essential features
  • Quality improvement

Step 2: Resizing

target_size = (224, 224)  # EfficientNetB0 input

Step 3: Normalization

pixels_normalized = pixels / 255.0  # [0, 1]

Data Augmentation

Technique Parameters Objective
Zoom ±20% Shooting variability
Horizontal Shift ±20% Position displacements
Vertical Shift ±20% Orientation variations
Rotation ±15° Robustness to rotations

Configuration:

datagen = ImageDataGenerator(
    rescale=1./255,
    zoom_range=0.2,
    width_shift_range=0.2,
    height_shift_range=0.2,
    validation_split=0.2
)

🏗️ Model Architecture

EfficientNetB0

EfficientNetB0 Architecture - Diabetic Retinopathy Detection 237 layers | 16 MBConv blocks | 5.3M parameters | Compound Scaling (Depth × Width × Resolution) 🩺 Input 224×224×3 Stem Conv 3×3, s=2 32 filters 112×112×32 Stage 1 MBConv1 k=3×3, ×1 16 filters 112×112×16 Stage 2 MBConv6 k=3×3, ×2 24 filters 56×56×24 Stage 3 MBConv6 k=5×5, ×2 40 filters 28×28×40 Stage 4 MBConv6 k=3×3, ×3 80 filters 14×14×80 Stage 5 MBConv6 k=5×5, ×3 112 filters 14×14×112 Stage 6 MBConv6 k=5×5, ×4 192 filters 7×7×192 Stage 7 (Final MBConv Stage) MBConv6 | k=3×3, ×1 | 320 filters SE Block + Swish Activation Output: 7×7×320 Stage 8 (Head) Conv 1×1: 320 → 1280 filters Global Average Pooling 7×7×1280 → 1280 features Custom Classification Head (Fine-tuned) Flatten: 1280 → Vector ↓ Dense (5 neurons) + Softmax No_DR | Mild | Moderate | Severe | Proliferate_DR ✓ Classification Result (0-4) 📊 MBConv Block Components 1. Expansion: 1×1 Conv (expand channels ×1 or ×6) 2. Depthwise: 3×3 or 5×5 Depthwise Conv 3. SE Block: Squeeze-and-Excitation (channel attention) 4. Projection: 1×1 Conv (reduce channels) + Batch Normalization + Swish Activation Hardware: NVIDIA RTX 4060 (8GB) | Adam Optimizer (lr=0.001) | Categorical Crossentropy | Training: 40 epochs
                            **EfficientNetB0 Architecture with custom classification**

Why EfficientNet?

Criteria EfficientNetB0 ResNet-50 VGG-16
Parameters 5.3M ✅ 25M 138M
Accuracy 97% ✅ 95% 94%
Speed Fast ✅ Medium Slow
Memory Low ✅ Medium High

Advantages:

  • ✅ Compound Scaling: Balanced optimization (depth/width/resolution)
  • ✅ Efficiency: Fewer parameters, same performance
  • ✅ Pre-training: ImageNet (transfer learning)
  • ✅ Speed: Real-time inference possible

Custom Classification Head

model = tf.keras.Sequential([
    # Pre-trained backbone
    EfficientNetB0(
        input_shape=(224, 224, 3),
        weights='imagenet',
        include_top=False
    ),
    
    # Custom classification head
    Flatten(),
    Dense(5, activation='softmax')  # 5 classes
])

Training Configuration

model.compile(
    optimizer='Adam',
    loss='categorical_crossentropy',
    metrics=['accuracy']
)

Hyperparameters:

  • Learning Rate: 0.001
  • Batch Size: 32
  • Epochs: 40
  • Optimizer: Adam
  • Loss: Categorical Crossentropy

🚀 Training Process

Training Strategy

Resources:

  • GPU: NVIDIA GeForce RTX 4060 (8GB VRAM)
  • Duration: ~2 hours for 40 epochs
  • Dataset Split: 80% train / 20% validation

Monitoring:

  • Loss and Accuracy at each epoch
  • Regular validation to avoid overfitting
  • Early stopping (patience: 10 epochs)

📊 Results & Performance

Quantitative Results

Metric Training Validation
Accuracy 98.5% 97.0% ✅
Loss 0.045 0.089
Precision 97.8% 96.5%
Recall 98.2% 96.8%

Per-Class Performance

Class Precision Recall F1-Score Support
No_DR 0.99 0.98 0.99 330
Mild 0.94 0.92 0.93 110
Moderate 0.96 0.95 0.96 146
Severe 0.93 0.94 0.94 88
Proliferate_DR 0.98 0.97 0.98 58

Confusion Matrix

            Predicted
            0    1    2    3    4
Actual  0 [323   4    2    1    0]
        1 [  5 101    3    1    0]
        2 [  2   4  139    1    0]
        3 [  1   2    2   83    0]
        4 [  0   1    0    1   56]

🛠️ Challenges & Solutions

Challenge 1: Class Imbalance

Problem: Underrepresented classes (Proliferate_DR: 8%)
Solution:

  • Weighted loss function
  • Aggressive data augmentation for minority classes
  • SMOTE (Synthetic Minority Over-sampling)

Challenge 2: Overfitting

Problem: Gap between training (98.5%) and validation (97%)
Solution:

  • Dropout layers (p=0.3)
  • Intensive data augmentation
  • Early stopping
  • L2 regularization

Challenge 3: Variable Image Quality

Problem: Lighting variations, resolution, noise
Solution:

  • Gaussian filtering beforehand
  • Systematic normalization
  • Augmentation simulating real variations

💼 Impact & Value

For Healthcare

✅ Automated early detection (Mild/Moderate stage)
✅ Improved accessibility to areas without specialists
✅ Cost reduction in diagnosis (60-70%)
✅ Automated monitoring of patient progression

Clinical Benefits

✅ Decision support for ophthalmologists
✅ Prioritization of urgent cases (Severe/Proliferate)
✅ Objectivity of diagnosis (elimination of human bias)
✅ Scalability for mass screening


🔮 Future Improvements

Short-Term:

  • Fine-tuning on EfficientNetB3/B7 (>98% accuracy)
  • Explainability (Grad-CAM for lesion localization)
  • REST API for hospital integration

Long-Term:

  • Multi-disease detection (AMD, glaucoma)
  • Mobile application for field screening
  • Federated Learning for privacy compliance
  • Electronic medical records integration

🛠️ Technical Stack

Deep Learning: TensorFlow 2.0, Keras
Computer Vision: OpenCV, PIL
Data Processing: NumPy, Pandas
Visualization: Matplotlib, Seaborn
Hardware: NVIDIA RTX 4060 (8GB VRAM)
Dataset: APTOS 2019 (Kaggle)


🎓 Skills Developed

  • Medical AI: Classification of ocular pathologies
  • Transfer Learning: Fine-tuning EfficientNet
  • Data Augmentation: Advanced techniques for medical imaging
  • Model Optimization: Hyperparameter tuning, regularization
  • Clinical Understanding: Interpretation of retinographies

📚 Key References

  1. EfficientNet (Tan & Le, 2019) - ICML
  2. APTOS 2019 - Kaggle Blindness Detection
  3. Diabetic Retinopathy Detection (Gulshan et al., 2016) - JAMA
  4. Deep Learning for Medical Imaging (Esteva et al., 2017) - Nature

📧 Contact

Team Members:

  • El Mehdi Hicham - mehdihicham736@gmail.com
  • Mohammed Imrane GRICH
  • Abdelrhafour EL MOUSSAOUI
  • Mouad AOUTIR

Supervisor: Pr. Souad EDDAROUICH
Institution: Faculty of Sciences, Ibn Tofail University

LinkedIn: linkedin.com/in/elmehdihicham
GitHub: github.com/MehdiHCH


🏆 Achievements

✅ 97% Accuracy on validation set
✅ Lightweight model (5.3M parameters)
✅ Inference time < 100ms per image
✅ Robust to acquisition variations
✅ Deployable on modest infrastructure


Early detection system for diabetic retinopathy combining medical precision and computational efficiency for democratized access to ophthalmological diagnosis.