COVID-19: Lung CT scan detection

Bacem Etteib
CodeX
Published in
7 min readJul 1, 2021

This is a quick article about my recent project on COVID-19 detection in CT scan images using CNNs. The results are quite satisfying since the model managed to achieve an accuracy of over 98%. You will find below all the necessary information on how to collect the data, build the model and deploy it.

Photo by Fusion Medical Animation on Unsplash

Abstract:

The diagnosis of COVID-19 through lung ct scans and chest X-ray images has proven its efficiency during the long fight with the virus. Radiologists analyze, on a daily basis, hundreds of computed tomography images to detect anomalies that can represent a potential COVID infection. This is a very demanding and time consuming task that can result in delays in hospitals. Thus, the current work is an attempt to put the pressure off the medical staff during the rapid surge of COVID-19 cases. With the use of Artificial Intelligence, a deep learning model has been trained to provide hospitals and laboratories with instant analysis for lung CT slices. The approach consists of classifying those images into three categories: Normal, Covid and CAP(Community Acquired Pneumonia). The proposed work uses a ResNet-50 pre-trained base model to perform the predictions. With further training using transfer learning technique, it was able to achieve an over 98% of accuracy.

1. Introduction:

Since its first appearance in China back in 2019, the world has been facing a global threat called COVID-19. The virus has caused so far tremendous damages on all aspects and changed heavily our daily lifestyle. While some countries managed to partially overcome the virus’ great impact by imposing strict regulations and providing the population with the vaccine, others have been struggling to find a way out and save people’s lives.

The medical staff has been exhausted and exposed to a high risk of infection since they are in a direct contact with the patients. Jingwen et al. [1] recommended chest computed tomography as the first-line imaging test for detecting COVID-19 pneumonia. The idea is to filter the potential COVID cases immediately after the CT scan results. The Radiologists role would still be as important as before but this time their effort will be more focused on the cases predicted as positive and with higher confidence level (model’s output). In addition, the application utilizes fewer computational resources which will be suitable for third world countries’ hospitals that lack those powerful resources. [2] were able to create a deep learning model that works in low-specifications machines but they sacrificed the accuracy rate to achieve such results. When combining both metrics, we are aiming to maximize the accuracy and minimize the processing power. The model has been deployed on a raspberry pi 3 and achieved great results within a very short amount of time. Such results are promising especially when we consider the limited specifications of this device and its cheap price. Finally, by providing radiologists with a tool that can rapidly and accurately classify CT scans, we limit the virus’ propagation at an early stage and save efforts during an outbreak.

2. Methodology:

2.1 Dataset:

The dataset used to train the model consists of data curated from 7 public datasets listed in the references. These datasets were used in previous projects related to COVID-19 diagnosis and have proven their efficiency. Therefore, by merging them all together, we are expecting to improve the generalization ability of deep learning methods. The dataset contains in total 7,593 COVID-19 images from 466 patients, 6,893 normal images from 604 patients, and 2,618 CAP images from 60 patients. Figure 1 represents the sample CT scan images collected from the used database.

Fig. 1

In the present study, it is necessary to make CT scan images compatible with our pre-trained transfer learning model input. In our case, the images come in 512*512*1 format. However, the ResNet-50 model requires a different size. To maintain the uniformity, input images were resized to 224*224 format. Afterwards, the OpenCV library was used to convert the grayscale images to RGB. Further, we normalize the pixel values for faster computation and to ensure that features are within the same range of values [0,1]. This is done according to this equation:

𝐼_𝑛𝑜𝑟𝑚=(𝐼𝑛−𝑚𝑖𝑛(𝐼𝑛))/(𝑚𝑎𝑥(𝐼𝑛)−𝑚𝑖𝑛(𝐼𝑛))

Fig. 2

We can notice that the proportion of number of cases in each class is different. The last category, CAP, have only 2,618 samples which is half the number of COVID cases. Therefore such an imbalance would result in a biased classification results. This will lead to an over-classification of the majority group due to its increased prior probability.

To avoid class sensitivity, data augmentation was performed. We will make use of the Augmentor library to double the number of samples in the third category. The library incorporates basic image preprocessing functionalities such as rotating, cropping and zooming. We have added a rotate() operation, that will execute with a probability of 80%, and have defined the maximum range by which an image will be rotated from between -10 and 10 degrees. In addition, a zoom() operation was performed with a 50% probability.

Fig. 3

Before performing data augmentation, we have splitted the data to a training set (80%) and testing set(20%). We reserved 20% of the training set to create the validation set in order to tune the model’s parameters and avoid overfitting. It is crucial to perform data preprocessing only after preparing the different sets for the main phases of model’s deployment.

2.2 Transfer learning

Given the enormous computational resources required to train a deep learning model from scratch on a large dataset, I used a famous technique in the deep learning field called Transfer Learning. It consists of using a pre-trained model on a base dataset as the starting point for a model on the second task of interest.

Fig.4 source: builtin

ResNet50 is one of the most popular pre-trained transfer learning-based CNN models proposed in 2015 by a group of Microsoft researchers. Its architecture consists of 5 stages each with a convolution and Identity block. Each convolution block has 3 convolution layers and each identity block also has 3 convolution layers. The ResNet-50 has over 23 million trainable parameters. [3].

Fig. 5 [4]

The network can take an input according to the format HEIGHT*WIDTH*3. Where height and width values must be 224*224 and the 3 refers to the number of channels in an RGB image. In addition, we used dropout technique to avoid overfitting and batch normalization to stabilize and speed up the learning process.

_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lambda (Lambda) (None, 224, 224, 3) 0
_________________________________________________________________
resnet50 (Functional) (None, 7, 7, 2048) 23587712
_________________________________________________________________
flatten (Flatten) (None, 100352) 0
_________________________________________________________________
batch_normalization (BatchNo (None, 100352) 401408
_________________________________________________________________
dense (Dense) (None, 256) 25690368
_________________________________________________________________
dropout (Dropout) (None, 256) 0
_________________________________________________________________
batch_normalization_1 (Batch (None, 256) 1024
_________________________________________________________________
dense_1 (Dense) (None, 128) 32896
_________________________________________________________________
dropout_1 (Dropout) (None, 128) 0
_________________________________________________________________
batch_normalization_2 (Batch (None, 128) 512
_________________________________________________________________
dense_2 (Dense) (None, 64) 8256
_________________________________________________________________
dropout_2 (Dropout) (None, 64) 0
_________________________________________________________________
batch_normalization_3 (Batch (None, 64) 256
_________________________________________________________________
dense_3 (Dense) (None, 3) 195
=================================================================
Total params: 49,722,627
Trainable params: 40,909,315
Non-trainable params: 8,813,312
_________________________________________________________________

2.3 Results

The results were in general satisfying. The best classification accuracy score, was 98.94% of training accuracy, and validation accuracy of 98.17% all obtained with the ResNet15 model on the used CT scan dataset. The performance increased significantly when applying data augmentation technique. Furthermore, data augmentation allowed us to overcome the problem of overfitting caused by the limited number of CT scan slices. Nevertheless, the model robustness can be further updated by trying to change the network’s architecture and implementing new techniques accordingly.

3. Conclusion:

This project proposes deep learning solution to classify lung CT scan slices into 3 classes. Initially, data preprocessing was performed on the used dataset. This involves techniques such as resizing and rotating. We,then, import our transfer learning base model ResNet50 and train it on the collected slices. The results are very promising especially when we consider the limited number of samples for each class. Thus, this work could be strongly susceptible to further improvements in the future.

REFERENCES:

  1. Jingwen Li, Xi Long, Xinyi Wang, Fang Fang, Xuefei Lv, Dandan Zhang, Yu Sun et al. Radiology indispensable for tracking COVID-19, 2021;.

2. Howard AG, Zhu M, Chen B, Kalenichenko D, Wang W, Weyand T, et al. Mobilenets: Efficient convolutional neural networks for mobile vision applications. arXiv preprint arXiv:170404861. 2017;.

3. Mathworks Documentation on ResNet50 architecture.

4. Baltruschat, Ivo & Nickisch, Hannes & Grass, Michael & Knopp, Tobias & Saalbach, Axel. (2019). Comparison of Deep Learning Approaches for Multi-Label Chest X-Ray Classification. Scientific Reports. 10.1038/s41598–019–42294–8.

--

--