COVID-19 Chest X-ray Diagnosis Using Transfer Learning with Google Xception Model

Andrew A Borkowski
The Startup
Published in
4 min readApr 11, 2020

Introduction

The COVID-19 pandemic, caused by the novel coronavirus SARS-CoV2, is rapidly spreading across the world and creating serious health and economic issues. Although the gold standard for diagnosing the COVID-19 disease is a polymerase chain reaction (PCR) assay, a chest x-ray may be a valuable addition to the diagnostic toolbox.
Using the COVID-Net Open Source Initiative dataset, I trained three machine learning models to differentiated between chest x-ray findings from COVID-19 disease, other non-COVID-19 pneumonia, and healthy lung. The jupyter notebooks for this project are available on my Github page.

Dataset

103 images of COVID-19, 500 images of non-COVID-19 pneumonia, and 500 images of the healthy lung were downloaded from links provided by the COVID-Net Github site. To balance the dataset, I expanded COVID-19 class to 500 images by slight rotation (probability=1, max rotation=5) and zooming (probability=0.5, percentage_area=0.9) of the original images using the Augmentor python package. 80% of images were assigned for training and 20% for validating the ML models.

Model 1

I coded the basic convolutional neural network with three sets of convolutional and pooling layers, followed by a fully-connected layer with 512 deep nodes and three output nodes.

The model achieved 98% training accuracy and 78% validation accuracy. Model overfitting was most likely due to limited datasets.

The classification report for the COVID-19 disease indicated recall (sensitivity) of 81% and precision (positive predictive value) of 94%.

Model 2

For this model, I used transfer learning with the Xception model pre-trained on the ImageNet dataset (1.2 million images in 1000 categories). Xception model, with depthwise separable convolution, is an advanced deep learning model that beat the competition in ImageNet classification. Transfer learning is a useful tool when you don’t have large enough dataset to train the model from scratch. One way is to remove a fully-connected layer from the pre-trained model like Xception and treat the rest of the model as a fixed feature extractor for the new dataset and only train the new classifier. Another way to use a pre-trained model is to train not only a new classifier but also fine-tune higher convolutional layers of the pre-trained model that are responsible for high-level feature extraction. I used the former way for Model 2 and the latter for Model 3. An excellent in-depth explanation of transfer learning can be found in this medium post.

The model achieved 82% training accuracy and 82% validation accuracy.

The classification report for COVID-19 disease indicated recall (sensitivity) of 99% and precision (positive predictive value) of 73%.

Model 3

This time I not only removed the classifier from the Xception model but also fine-tuned the last three layers of the Xception feature extractor on my dataset. For proper fine-tuning, I decreased the default learning rate of Adam optimizer by 10x.

The model achieved almost 100% (99.92%) training accuracy and 86% validation accuracy.

The classification report for the COVID-19 disease indicated recall (sensitivity) of 83% and precision (positive predictive value) of 94%, the best results for COVID-19 disease diagnosis of all three models.

Conclusion

COVID-19 pandemic is a serious and tragic event that is causing a lot of suffering all around the world. AI may be one of the tools that could be used to fight this devastating enemy. In this post, I explained how to use transfer learning with the Xception model to classify COVID-19 radiological chest images successfully.

I sincerely wish the best of health to all the medium readers and their families in this time of crisis.

--

--