Home

Awesome

Classification and Gradient-based Localization of Chest Radiographs

cover

Contents

Introduction

A team of radiologists from New Orleans studied the usefulness of Chest Radiographs for diagnosing COVID-19 compared to the reverse-transcription polymerase chain reaction (RT-PCR) and found out they could aid rapid diagnosis, especially in areas with limited testing facilities [1].<br> Another study found out that the radiographs of different viral cases of pneumonia are comparative, and they overlap with other infectious and inflammatory lung diseases, making it hard for radiologists to recognize COVID‐19 from other viral pneumonia cases [2].<br> This project aims to make the former study a reality while dealing with the intricacies in the latter, with the help of Deep Learning.<br>

Overview

The project uses the COVID-19 Radiography Database [3] as it's dataset. It has a total of 21165 Chest X-Rays (CXRs) belonging to 4 different classes (COVID-19, Lung Opacity, Normal and Viral Pneumonia).<br> Three top scoring CNN architectures, VGG-16 [4], ResNet-18 [5] and DenseNet-121 [6], trained on the ImageNet Dataset [7], were chosen for fine-tuning on the dataset.<br> The results obtained from the different architectures were then evaluted and compared.<br> Finally, with the help of Gradient weighted Class Activation Maps (Grad-CAM) [8] the affected areas in CXRs were localized.<br>

Steps

  1. Dataset Exploration
  2. Split the dataset
    TypeCOVID-19Lung OpacityNormalViral PneumoniaTotal
    Train3496589210072122520685
    Val60606060240
    Test60606060240
  3. Fine-tune VGG-16, ResNet-18 and DenseNet-121
    1. Define Transformations
    2. Handle imbalanced dataset with Weighted Random Sampling (Over-sampling)
    3. Prepare the Pre-trained models
    4. Fine-tune step with Early-stopping
      • Hyper-parameters
        Learning rate0.00003
        Batch Size32
        Number of Epochs25
      • Loss FunctionOptimizer
        Categorical Cross EntropyAdam
    5. Plot running losses & accuracies
      • ModelSummary Plot
        VGG-16vgg_plot
        ResNet-18res_plot
        DenseNet-121dense_plot
  4. Results Evaluation
    1. Plot confusion matrices
    2. Compute test-set Accuracy, Precision, Recall & F1-score
    3. Localize using Grad-CAM
  5. Inference

Results

<table> <tr> <th></th> <th>VGG-16</th> <th>ResNet-18</th> <th>DenseNet-121</th> </tr> <tr> <td>
Pathology
COVID-19
Lung Opacity
Normal
Viral Pneumonia
</td> <td>
AccuracyPrecisionRecallF1-Score
0.99560.98331.00000.9916
0.95820.88330.94640.9138
0.96220.96670.89230.9280
0.99130.98330.98330.9833
</td> <td>
AccuracyPrecisionRecallF1-Score
0.98710.96670.98300.9748
0.96640.86671.00000.9286
0.96641.00000.88230.9375
0.99571.00000.98360.9917
</td> <td>
AccuracyPrecisionRecallF1-Score
0.99570.98331.00000.9916
0.96230.91670.93220.9244
0.96230.95000.90470.9268
0.99570.98331.00000.9916
</td> </tr> <tr> <td>
TL;DR
Train set
Test set
</td> <td>
Total Correct PredictionsTotal Accuracy
2036298.44%
22995.42%
</td> <td>
Total Correct PredictionsTotal Accuracy
2063999.78%
23095.83%
</td> <td>
Total Correct PredictionsTotal Accuracy
2054099.30%
23095.83%
</td> </tr> <tr> <td>Confusion Matrices</td> <td>

vgg_confmat

</td> <td>

res_confmat

</td> <td>

dense_confmat

</td> </tr> </table>
originalvgg_camres_camdense_cam
<sup>COVID-19 infected CXR</sup><sup>VGG-16</sup><sup>ResNet-18</sup><sup>DenseNet-121</sup>

Usage

git clone 'https://github.com/priyavrat-misra/xrays-and-gradcam.git' && cd xrays-and-gradcam/
pip install -r requirements.txt
python overlay_cam.py --help
usage: GradCAM on Chest X-Rays [-h] [-i IMAGE_PATH]
                               [-l {covid_19,lung_opacity,normal,pneumonia}]
                               -m {vgg16,resnet18,densenet121}
                               [-o OUTPUT_PATH]

Overlays given label's CAM on a given Chest X-Ray.

optional arguments:
  -h, --help            show this help message and exit
  -i IMAGE_PATH, --image-path IMAGE_PATH
                        Path to chest X-Ray image.
  -l {covid_19,lung_opacity,normal,pneumonia}, --label {covid_19,lung_opacity,normal,pneumonia}
                        Choose from covid_19, lung_opacity, normal &
                        pneumonia, to get the corresponding CAM. If not
                        mentioned, the highest scoring label is considered.
  -m {vgg16,resnet18,densenet121}, --model {vgg16,resnet18,densenet121}
                        Choose from vgg16, resnet18 or densenet121.
  -o OUTPUT_PATH, --output-path OUTPUT_PATH
                        Format: "<path> + <file_name> + .jpg"
python overlay_cam.py --image-path ./assets/original.jpg --label covid_19 --model resnet18 --output-path ./assets/dense_cam.jpg
GradCAM generated for label "covid_19".
GradCAM masked image saved to "./assets/res_cam.jpg".

Conclusions

References