Diabetic retinopathy (DR) is an illness which causes damages to retina. The goal of this project is to build a generic framework to classify nonreferable (NRDR) and referable (RDR) diabetic retinopathy based on fundus images with deep learning algorithms.
Preventing some new student from simply copying and pasting. Code is hidden.
- BN: We were using Batch Normalization (BN) in our network, which is sensitive to small batch size, may try bigger batch size for better performance.
- Skip-connection: Skip-connection in ResNet may not bring us a big advantage in such kind of shallow network.
- Imbalanced dataset: We could use weighted loss for different classes instead of simple oversampling to handle the imbalanced dataset.
- Data augmentation: too much data augmentation may damage performance in a small dataset.
- Optimizer: Maybe SGD+momentum+weight decaying+multi-step schedule is a better option than Adam. Adam converges faster but may not achieve optimum.
- Some other tricks: Label smoothing etc.
Indian Diabetic Retinopathy Image Dataset (IDRiD)
- Redefine labels for binary classification
- Use the left and right border of retina to crop the images and resize them to 256 * 256
- Oversampling to balance the dataset
- Use TFRecord to load data efficiently
- Reducing the disk space usage 212.2MB --> 21.9MB
- Rotation, Shift, Zoom, Brightness, Flipping, Shearing
ResNet is a kind of convolutional neural network with skip-connection, which has shown high accuracy for classification tasks.
Our network is a simplified version of ResNetV2.
Architecture |
---|
7 * 7 Conv(strides=2), BN, ReLU |
3 * 3 Max pooling(strides=2) |
ResBlock(strides=2) ch=16 |
ResBlock(strides=2) ch=32 |
ResBlock(strides=2) ch=64 |
ReLU, Global average pooling |
Dense(unit=2), Softmax |
Loss function: sparse cross-entropy
- Accuracy
- Confusion Matrix
- Logging with abseil
- Configuration with gin instead of hard coding
- AutoGraph, average epoch time: 11.92s --> 7.18s
- Deep visualization(Grad-CAM)
- Grid search for hyperparameter tuning(TensorBoard)
- Use Adam optimizer to train our network for 300 epochs
- Save checkpoint for every 5 epochs
- Hyperparameter tuning - grid search
- Based on above best hyperparameters, it's still underfitting , use small learning rate=1e-5 and stronger data augmentation for further training(50 epochs)
Project is created with:
- Python 3.6
- Tensorflow 2.0.0
Code is hidden.
Manipulate confin.gin
to switch from different modes. And usepython3 main.py
to start the program.
Code is hidden.
Under this mode, no checkpoint will be saved and nothing will be visualized. And grid search for hyperparameter optimization will be executed.
main.tuning = True
main.hparams = {'HP_BS': 8,
'HP_LR': 1e-3} # these hyperparameters will not be executed.
main.num_epoch = 1 #the epochs you want to run#
Code is hidden.
Under this mode, you will have control of the hyperparameter for a single run. Checkpoints will be saved for every 5 epochs. If there is previous checkpoint, it'll be restored automatically. A random image in test set will be visualized by Grad-CAM.
main.tuning = False
main.hparams = {'HP_BS': 8,
'HP_LR': 1e-3} #batch size and learning rate you want to use#
main.num_epoch = 1 #epochs you want to run#
Balance accuracy on test set: 82.2%
Grad-CAM Result
E.g., for RDR images, our network mainly focuses on hard exudates on retinal fundus, which is reasonable.
- CAO Shijia, https://github.com/scarlettcao
- ZHONG Liangyu, https://github.com/LEGO999