Skip to content

Jalil03/Blurry2Clear

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘οΈ Blurry2Clear – Deep Learning-Based Diabetic Retinopathy Classification

Welcome to Blurry2Clear, a deep learning project that aims to automate the classification of Diabetic Retinopathy (DR) stages from retinal fundus images using powerful computer vision techniques. This project is based on transfer learning with ResNet-50 and explores various training strategies to tackle data imbalance and optimize performance on the APTOS 2019 Blindness Detection dataset.


🩺 Project Objective

Diabetic Retinopathy is one of the leading causes of blindness worldwide, especially in diabetic patients. Early detection is critical for timely treatment and vision preservation. This project seeks to build a robust and interpretable model that can:

  • Classify retinal fundus images into five stages of Diabetic Retinopathy (0 to 4).
  • Mitigate the challenges of data imbalance using advanced training techniques.
  • Improve prediction performance through progressive model experimentation.

πŸ“‚ Repository Structure

This repository contains four core Jupyter notebooks, each representing a different approach to model training and evaluation:


1. main_aptos.ipynb β€” 🧠 Baseline + Improved Pipeline

This is the main notebook that defines the end-to-end pipeline. It includes:

  • Two versions:
    • A baseline ResNet-50 classifier with default training.
    • An improved pipeline with better preprocessing, early stopping, and tuned hyperparameters.
  • Techniques used:
    • Image normalization & augmentation (RandomCrop, Flip, ColorJitter).
    • Transfer learning using pretrained ResNet-50 from torchvision.models.
    • Replacement of the final classification layer (model.fc) to adapt to 5 classes.
    • Early stopping and loss tracking for stable training.
  • Output: Accuracy scores, loss curves, and a confusion matrix.

2. approche1.ipynb β€” πŸ” Partial Fine-Tuning (Layer4 + FC only)

This notebook evaluates the impact of fine-tuning only the deeper layers of ResNet-50:

  • Frozen layers: All layers except layer4 and the final fc layer.
  • Aimed to:
    • Reduce overfitting.
    • Speed up training on large datasets (over 26,000 images).
  • Findings:
    • Test Accuracy: ~74%
    • Precision and recall are skewed due to class imbalance.
  • Confusion matrix provided for per-class error analysis.

3. approche2.ipynb β€” βš–οΈ Focal Loss + Weighted Sampling Strategy

This notebook addresses severe class imbalance using:

  • Focal Loss:
    • Helps the model focus on hard-to-classify minority classes.
    • Gamma parameter set to 2.0 for down-weighting easy examples.
  • WeightedRandomSampler:
    • Balances the frequency of classes in each training batch.
  • Limitations:
    • Trained on a small subset (3,000 images) to test strategy feasibility.
    • Accuracy was low but recall for rare classes improved significantly.
  • Key takeaway: A promising direction with more tuning/data.

4. approche3.ipynb β€” πŸ§ͺ Full Model + Best Performance

This approach produced the best overall results and serves as the final model candidate:

  • Full training on all layers of ResNet-50.
  • Combines:
    • CrossEntropyLoss with class weights computed from class distribution.
    • WeightedRandomSampler for balanced batch composition.
    • EarlyStopping for convergence monitoring.
  • Dataset: Trained on ~21,400 preprocessed images.
  • Final Results:
    • Accuracy: ~78.41%
    • Strong balance between precision, recall, and F1-score.
    • Stable learning curves and effective generalization.
  • Chosen as the preferred model for evaluation and inference.

πŸ“Š Evaluation Metrics

We evaluate the performance using standard classification metrics:

  • βœ… Accuracy: Overall proportion of correct predictions.
  • πŸ“ˆ Precision / Recall / F1-score (macro-averaged across 5 classes).
  • πŸ“‰ Confusion Matrix: Visual analysis of class-wise prediction errors.
  • πŸ“‰ Loss & Accuracy Curves: Monitored across epochs for both training and validation sets.

🧠 Deep Learning Techniques

The project integrates several key AI and ML techniques:

Component Technique Used
Feature Extraction Pretrained ResNet-50
Transfer Learning Frozen base layers / Fine-tuning variants
Image Preprocessing Resize, Normalize, Data Augmentation
Loss Functions CrossEntropyLoss, FocalLoss
Imbalance Handling Weighted Losses, WeightedRandomSampler
Evaluation Scikit-learn metrics, Matplotlib plots

πŸ“¦ Setup & Dependencies

Install the required packages using pip:

pip install torch torchvision matplotlib scikit-learn numpy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published