For Running the script follow the instructions here or run the code directly using
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
- 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
- Model Architecture
- Training Routine
- Model CallBacks:
- Check point Callback - For saving model at desired interval(epoch frequency)
- Tensorboard Callback - For logging training stats,Profiling
- CSV Logger Callback - To save training logs in a csv file
- Training from a check point
- Initial epoch here is the point at which the training was interrupted
- Evaluation
- Data Augmentation
- Vertical Flip
- Horizontal Flip
- Box Crop
- Rotate
- Deep Visualization
- GradCAM
- Hyper Parameter Tuning
- Grid Search (Epochs, Number of dense neurons, stride, Learning rate)
- After Image processing and data augmentation:
Processed and Augmented Images
-
Model Architecture
- Model based on ResNET50v2 (Transfer learning).
- 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
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
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.
-
To Train the model, change the train FLAG in
main.py
toTrue
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')
- To log the data , specify path to tensorboard callback, model chekpoint call back, CSVlogger call back in
-
For performing hyperparamter Tuning, change the hparam_tune FLAG in
main.py
toTrue
flags.DEFINE_boolean('hparam_tune', True, 'Specify if its hyper param tuning.')
-
For Training the model based on ResNET50v2 change the Transfer_learning FLAG in
main.py
toTrue
flags.DEFINE_boolean('Transfer_learning', True, 'to use transfer learning based model, train flag must be set to true to fine tune pretrained model')
-
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.')
- Change the path of the pretrained model here in
-
.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