Giter Site home page Giter Site logo

diabetic_retinopathy's Introduction

Diabetic Retinopathy Classification Using DNN

For Running the script follow the instructions here or run the code directly using Open In Colab

Change the hyper parameters in constants.py

This project was exported from pycharm, environment based on python 3.8 was used. Make sure Source directory is diabetic_retinopathy

  1. Input Pipeline
    • IDRID Dataset(Training set Images- 413, Test set Images-103)
    • Image Resize (to 256*256)
    • Image crop (Box crop)
    • Image Normalization
    • Class balancing
  2. Model Architecture
  3. Training Routine
  4. Model CallBacks:
  5. Training from a check point
    • Initial epoch here is the point at which the training was interrupted
  6. Evaluation
  7. Data Augmentation
    • Vertical Flip
    • Horizontal Flip
    • Box Crop
    • Rotate
  8. Deep Visualization
    • GradCAM
  9. Hyper Parameter Tuning
    • Grid Search (Epochs, Number of dense neurons, stride, Learning rate)

Outputs from several stages of project

  • After Image processing and data augmentation:

Processed and Augmented Images

  • Model Architecture

    1. Model based on ResNET50v2 (Transfer learning).
    2. Model based on Blocks of Conv+BatchNorm+Maxpool (Only 453K parameters)

    Custom Architecture based on blocks of Conv+BatchNorm+Maxpool (ii)

  • Training Results

    • Model based on Blocks of Conv+BatchNorm+Maxpool

    Accuracy plot for Custom model (on left) and ResNET50v2 based model (on right) [epochs vs accuracy]

  • Results and Evaluation

    • Test accuracy - 77.8% (Custom Model), 81.55% (Finetuned on ResNET50v2)

    Confusion Matrix

    precision recall f1-score Support
    NRDR 0.73 0.82 0.77 39
    RDR 0.88 0.81 0.85 64
    accuracy 0.82 0.82 0.82 103
    macro avg 0.80 0.82 0.81 103
    weighted avg 0.82 0.82 0.82 103

    Classification Report

  • Deep Visualization

    Original Image, GradCAM output, Overlay

  • Hyperparameter optimization

    Original Image, GradCAM output, Overlay

Instructions to run the script:

Before running the script Install the requirments from requirements.txt using pip install -r requirements.txt

  • Make the following changes in main.py based on the Mode(training mode, hyper parameter tuning mode, finetuning mode, evaluation mode) you want to run the script in.

    1. To Train the model, change the train FLAG in main.py to True
      flags.DEFINE_boolean('train', True, 'Specify whether to train or evaluate a model.')

      • To log the data , specify path to tensorboard callback, model chekpoint call back, CSVlogger call back in constants.py dir_all_logs = 'log_dir'
        dir_fit = os.path.join(dir_all_logs, 'fit')
        dir_cpts = os.path.join(dir_all_logs, 'cpts')
        dir_csv = os.path.join(dir_all_logs, 'csv_log')
    2. For performing hyperparamter Tuning, change the hparam_tune FLAG in main.py to True

      flags.DEFINE_boolean('hparam_tune', True, 'Specify if its hyper param tuning.')

    3. For Training the model based on ResNET50v2 change the Transfer_learning FLAG in main.py to True

      flags.DEFINE_boolean('Transfer_learning', True, 'to use transfer learning based model, train flag must be set to true to fine tune pretrained model')

    4. For Evaluating the pretrained model

      • Change the path of the pretrained model here in main.py to desired path.

      flags.DEFINE_boolean('train', False, 'Specify whether to train or evaluate a model.')

Directory Structure for diabetic_retinopathy :

.diabetic_retinopathy
├── ./IDRID_dataset
│   ├── ./IDRID_dataset/CC-BY-4.0.txt
│   ├── ./IDRID_dataset/LICENSE.txt
│   ├── ./IDRID_dataset/images
│   │   ├── ./IDRID_dataset/images/test
│   │   └── ./IDRID_dataset/images/train
│   └── ./IDRID_dataset/labels
│       ├── ./IDRID_dataset/labels/test.csv
│       └── ./IDRID_dataset/labels/train.csv
├── ./Poster_Diabetic_Retionopathy_.pdf
├── ./README.md
├── ./configs
│   └── ./configs/config.gin
├── ./constants.py
├── ./evaluation
│   └── ./evaluation/eval.py
├── ./hp_log_dir
│   ├── ./hp_log_dir/cpts
│   ├── ./hp_log_dir/csv_log
│   ├── ./hp_log_dir/fit
│   ├── ./hp_log_dir/hparam_tuning
│   └── ./hp_log_dir/results
├── ./hyper_parameter_tuning
│   └── ./hyper_parameter_tuning/hparam_tuning.py
├── ./input_pipeline
│   ├── ./input_pipeline/datasets.py
│   ├── ./input_pipeline/datasets2.py
│   └── ./input_pipeline/preprocessing.py
├── ./log_dir
│   ├── ./log_dir/checkpoint
│   ├── ./log_dir/cpts
│   ├── ./log_dir/csv_log
│   ├── ./log_dir/fit
├── ./main.py
├── ./media
├── ./models
│   ├── ./models/architecture.py
│   └── ./models/transfer_learning_architecture.py
├── ./requirements.txt
├── ./results
│   ├── ./results/classification_report.csv
│   └── ./results/confusionmatrix.png
├── ./visualization
│   └── ./visualization/deep_vis.py
└── ./weights
    ├── ./weights/20201222-220802_ADAM_epochs_100_test_acc_78.h5
    ├── ./weights/20201224-212524_ADAM_epochs_10_test_acc_81_55_cm_32_52.h5
    └── ./weights/fullmodel_tl_82_acc.h5

diabetic_retinopathy's People

Contributors

saitejamalyala avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.