Introduction

Coronavirus disease scientifically called as (COVID-19) is an infectious disease caused by a newly discovered coronavirus. Most people infected with the COVID-19 [1] virus will experience mild to moderate respiratory illness and recover without requiring special treatment.

Older people, and those with underlying medical problems like cardiovascular disease, diabetes, chronic respiratory disease, and cancer are more likely to develop serious illness. COVID-19 affects different people in different ways. Most infected people will develop mild to moderate illness and recover without hospitalization. Most common symptoms are Fever, dry cough, tiredness and less common symptoms are aches and pains, sore throat, diarrhea, conjunctivitis, headache, loss of taste or smell, a rash on skin, or discoloration of fingers or toes.

COVID-19, at first is reported as pneumonia disease, has become an epidemic for world. The first case was discovered in Wuhan (China). Virus spread in china in just 30 days and reached over all over world by April 2020. It is proved that coronaviruses generated through animals can be transmitted to humans. The infected people suffer from failure of respiratory system. On March 11, 2020, novel coronavirus (COVID-19) outbreak is declared as a global pandemic by World Health Organization (WHO). Early diagnosis of this disease is possible using either computed tomography (CT) or X-ray [2]. In the beginning, hospitals had inadequate test kits, because of that doctors were compelled to make diagnosis on basis of X-ray and CT. Combination of clinical image features with lab tests results is found beneficial in detection of COVID-19. Chest X-ray images obtained from COVID-19 cases contain valuable information for diagnostics. Considering the fact that X-ray imaging systems are more prevalent and cheaper than CT scan systems, this research uses chest X-rays to screen COVID-19.

X-rays and the CT scans [3] in COVID-19 patients show small patchy translucent white areas in the lung—what the radiologists call “GGO or ground glass opacities”. They are more commonly found in outer and lower parts of lungs. In some patients, the CT scans show a crisscross pattern of white lines called a “crazy paving” appearance. These changes completely resolve back to normal in most patients as they get better. But if the patient’s condition worsens, the changes may extensively involve one or both the lungs causing “white out” lungs, and this is the time when the patient typically needs intubation and ventilator support. In such cases, it is common to see a certain degree of residual scarring in lungs that may persist for a lifetime in a patient. Radiological scans give the physician key inputs about the progression of the disease. Serial X-rays can predict the course of the patient at the hospital and show a red alert in case the condition worsens. Figure 1a–c shows serial radiological progression seen with COVID-19 [4].

Fig. 1
figure 1

a Normal posterior–anterior chest radiograph [4] of patient, a man 50 years of age (taken up to 12 months before admission in hospital). b Chest radiograph of patient when he developed COVID-19 pneumonia[4]—(day 0 of admission), white arrows showing ground glass opaqueness in the periphery (outer third of the lung) of both lungs in the mid and lower zones (white arrows), black arrow showing preservation of lung marking, and linear opacity in the periphery of the left mid zone. c Chest radiograph of patient on day 10 of admission, showing progression to severe covid-19 pneumonia [4]: patient intubated with endotracheal tube, central lines, and nasogastric tube in situ. Outlined arrow shows dense consolidation with loss of lung markings is now seen behind the heart in the left lower zone. White arrows show extension of the peripheral ground glass changes seen in b can be seen in the periphery of the right mid and lower zones and the left mid zone

In this study, a machine learning model is proposed for the diagnosis of COVID-19. The proposed model (CvDeep) requires unprocessed chest X-ray images. The number of images used for training of model are 125. The images are preprocessed for final diagnosis with pertained models. It is observed that it is difficult to detect COVID-19 in early stage using images analysis, but if pre trained deep learning models are used, it can improve the accuracy of detection.

Related Work

Machine learning provides approaches, methods, and tools [5] that can assist in solving diagnostic and analytical problems in medical field. It is also being used for data analysis, such as detection of symmetries in the data, understanding of information used in the Intensive Care Unit for active and competent monitoring. Effective implementation of ML methods can help medical experts using computer-based systems giving quality of medical care.

Deep learning supports automatic feature extraction [6] so it is easy to understand what kind of deep networks are suitable for a given problem. Deep learning algorithms have great successes in various fields including medical imaging analysis. Deep learning, is incredible [7] to identify, classify, and quantify patterns in medical images. Deep learning techniques have been useful in detection of cancer, brain, lung diseases from chest X-ray images [8]. As number of radiologists are limited it becomes difficult to provide expertise opinion in COVID-19 cases rapidly. As the number of patients infected by COVID-19 is increasing day by day, there is need of automated detection systems based on AI. The technology developed can act as assistance to radiologists and it can reduce the time for diagnosis [9] and overcome the limitation of less number of test kits.

Research work is ongoing on radiology images for detection of COVID-19. COVID-Net (92.4% accuracy for classification) is a deep model proposed by Wang and Wong [10]. COVIDX-Net model [11] has seven CNN models.The model [12] proposed by Ioannis et al. obtained 93% accuracy for binary classification. Deep convolutional model [13] achieved a 98% accuracy in COVID-19 detection. It is observed that convolutional neural network (CNN) [14] along with support vector machine (SVM) classifier gives best features.

Data Set Collection

Image Data Set (X-ray Images)

In this study, image data set consists of covid-19 patients lungs X-ray images [15] (478 images) and COVID-19 image database by developed by Cohen JP [16] (925 images). The data set has 478 + 925 = 1403 images (985 X-ray images with COVID-19 positive diagnosis).

Corona Virus Data Set

Image folder has images in various format (.jpeg,.jpg and.png) and comma separated value (.csv) file that contains information for each of the images, type of image (either X-ray or CT Scan), view that gives type of taking the X-ray (PA, L, Axial, AP, etc.), disease label (COVID-19, SARS, Klebsiella, Nocardia, Mycoplasma, Influenza, ARDS, Pneumocystis, Streptococcus etc.), among others.

Training and Validation images are divided in two folders (covid and nocovid). As the purpose of research work is to detect COVID-19, save all the images labeled as such in the covid subfolders and any other type of virus (SARS, ARDS, Pneumocystis, etc.) in the nocovid subfolders. Figure 2 shows different X-ray images of covid and nocovid category.

Fig. 2
figure 2

Different X-ray images of covid and nocovid category

At first to create COVID-19 X-ray imaging data set, comma separated value (.csv) file was studied. Images labeled as modality CT (Computed Tomography) are saved in CT folder. 70% of the total images are used for training, 15% for validation and remaining 15% for test. The finding, view and modality columns are used to create training, validation and testing data. The data set was divided into subfolders covid (COVID-19 positive) and nocovid (COVID-19 Negative). As there are no images of healthy patients Kaggle’s chest X-ray imaging data set [17] is downloaded for creating validation and test data-rays of normal patients (88 images) and X-rays of pneumonia patients (88 images) are randomly selected to validation and test folder. The folders has 44 images of each class (covid and nocovid). In all image data set, had 584 images left in total. The training data set consists of 177 positive X-ray images for COVID-19 and 176 X-ray images of patients without COVID-19.

The Proposed Model

The CvDeep model will train an image classifier for detection of COVID-19, using X-rays images. Trained image classifier is used in an application. The images are transformed with a maximum rotation of 25°. The images are processed with noise removal algorithm. The suppression of noise from images means 2d spatial processing which applies to high frequency signals. The noise exists in low signal areas and phase out in high signal areas. It is the process of removing or reducing the noise from the image. Figure 3 shows flow diagram for various image transformation steps.

Fig. 3
figure 3

Image transformation flow diagram

The images are further horizontally rotated. Common error in image preprocessing is overfitting of model. The transformation avoids overfitting. Because of overfitting (fits too well to training set), model fails for prediction of new examples. Training accuracy will be higher than the accuracy on the validation/test set. One solution to above problem is use of augmentation. It considers transformed versions of images in the training data set that belong to the same class as the original image.

The images are loaded into an ImageDataBunchobject [18]. This object allows us to:

  1. 1.

    Directly load the images from a folder,

  2. 2.

    Define the number of images per batch,

  3. 3.

    Identify which ones are for training, validation and testing,

  4. 4.

    Perform the previously defined transformations,

  5. 5.

    Make all the images have the same size, etc.

Batch size is selected as three rows and three columns. Random images are shown for every single running state of program. There are 584 total images having two classes covid, nocovid and total 408 images to train, 88 to validate and 88 to test. Images are further preprocessed after augmentation The steps consist of remove black pixels from image, crop the image, remove the row and column in which black portion is more in number. The process is repeated for all pixels. Equal number of rows and columns removed. Thus image ratio is maintained. Figure 4 shows the CvDeep model for COVID-19 detection.

Fig. 4
figure 4

CvDeep model for COVID-19 detection

Building and Training the Classifier

The data set created will use one of the pre-trained models to obtain the characteristics of the image. Some of the more popular pre-trained models include SqueezeNet, DenseNet, ResNet, and AlexNet. These model does not need large amounts of computing power, time and can easily find the right training technique to optimize weights for network. In training phase, the parameters like hidden neurons, learning rate, and momentum were changed for obtaining improved classification result.

The model is initially trained for four epoch (the amount of times user want to train). It is number of times that all data goes through the network in the forward and backward directions getting update of weights; it takes only 1 min 21 s of training. After saving the model for future use we call it stage 1 model. The appropriate values of learning parameters of the network are obtained through various combinations.

Image Classifier with Densenet

The name “DenseNet” refers to Densely Connected Convolutional Networks. Traditional convolutional networks [19] with n layers have n connections; one between each layer and its subsequent layer. In DenseNet each layer connects to every other layer in a feed-forward fashion, meaning that DenseNet has n(n + 1)/2 connections in total. For each layer the preceding layers feature maps are used as inputs.

Dense Blocks

DenseNet boasts one big advantage over conventional deep CNNs: the information passed through many layers will not be washed-out or vanish by the time it reaches the end of the network. As the layers in the network receive feature maps from all the preceding layers, the network will be thinner and more compact. DenseNet architecture [20] does provide the best illustration of images. They are easier for training. Figure 5 shows top losses from DenseNet model indicating prediction /actual/loss/probability for (4 epoch).

Fig. 5
figure 5

Top losses from DenseNet model indicating prediction /actual/loss/probability for (4 epoch)

In general, it is a convolutional network to which data object is passed, it uses the pre-trained model and error rate metric with the data set validation. There are other metrics that could be used to review the information. If we take as an example the image of the first column and third row, it prints four things prediction/current/loss/probability of current class. These parameters are used for verification of results.

Some layers are called frozen layers, because the weights of those layers were not changed. So results are obtained quickly. These layers are extra layers to the end of the architecture, and only these layers are trained.

In general network must be trained with following steps with all the layers.

  1. 1.

    Unfreeze the weights of all layers so that you can update them with training.

  2. 2.

    Find the best learning rate indicating how fast we are updating the parameters in our model. Figure 6 shows plot of Loss against Learning Rate (DenseNet model). Figure 7 shows plot losses (DenseNet model).

  3. 3.

    Learning rate (LR) values are plotted. Initially LR value are set in certain range. First layers trained at a learning speed of lowest LR and the last layers are trained at a speed of highest value LR. The other values are distributed in between all other layers in equal proportion. Figure 8 shows plot losses after selection of LR (DenseNet model)

  4. 4.

    Model is now trained for ten epochs so error rate is reduced to 3% and there is improvement of 7%.

  5. 5.

    The image classifier is saved as stage 2 model. The images are classified using this stage2 model. Figure 9 top losses from DenseNet model indicating prediction /actual/loss/probability for (10 epoch)

  6. 6.

    Any particular image is classified as covid or nocovid using these model.

Fig. 6
figure 6

Plot of loss against Learning Rate (DenseNet model)

Fig. 7
figure 7

Plot losses (DenseNet model)

Fig. 8
figure 8

Plot losses after selection of LR (DenseNet model)

Fig. 9
figure 9

Top losses from DenseNet model indicating prediction /actual/loss/probability for (10 epoch)

Image Classifier with AlexNet

AlexNet, which employed an eight-layer CNN [21], won the ImageNet Large Scale Visual Recognition Challenge 2012 by a phenomenally large margin. This network showed, for the first time, that the features obtained by learning can transcend manually designed features, breaking the previous paradigm in computer vision. Figure 10 shows top losses from AlexNet model indicating prediction /actual/loss/probability for (4 epoch) stage 1 of model. The activation used is the Rectified Linear Unit (ReLU). AlexNet has a similar structure to that of LeNet, but uses more convolutional layers and a larger parameter space to fit the large-scale ImageNet data set.

Fig. 10
figure 10

Top losses from AlexNet model indicating prediction /actual/loss/probability for (4 epoch)

Today AlexNet has been surpassed by much more effective architectures but it is a key step from shallow to deep networks that are used nowadays. Figure 11 shows plot of loss against Learning Rate. Figure 12 shows plot of losses. Dropout, ReLU and preprocessing were the other key parameters in achieving excellent performance in computer vision tasks. Key Steps in AlexNet classifier model generation are:

  • Data augmentation (cropping and mirroring) is carried out to reduce over-fitting also drop-out layers (connection is dropped, while training with probability p = 0.5) is used.

  • Max-pooling layer is used after each CONV layer.

  • AlexNet introduced Local Response Normalization (LRN). The idea behind LRN is to carry out a normalization in a neighborhood of pixel amplifying the excited neuron while dampening the surrounding neurons at the same time.

    Figure 13 shows plot of losses after selection of LR.

  • Model is trained for ten epochs so error rate is reduced to 3% and there is improvement of 7%.

  • The image classifier is saved as stage 2 model. The images are classified using this stage 2 model. Any particular image is classified as covid or nocovid using this model. Figure 14 shows top losses from AlexNet indicating prediction/actual/loss/probability for (10 epoch).

Fig. 11
figure 11

Plot of loss against Learning Rate (AlexNet model)

Fig. 12
figure 12

Plot losses (AlexNet model)

Fig. 13
figure 13

Plot losses after selection of LR (AlexNet model)

Fig. 14
figure 14

Top losses from AlexNet indicating prediction /actual/loss/probability for (10 epoch)

Image Classifier with ResNet

A residual neural network (ResNet) [22] is an artificial neural network (ANN). ResNet, short for Residual Networks is a classic neural network used as a support for many image processing tasks. Figure 15 shows top losses from ResNet model indicating prediction /actual/loss/probability for (4 epoch) stage 1 of model.

Fig. 15
figure 15

Top losses from ResNet indicating prediction /actual/loss/probability for (4 epoch)

The fundamental breakthrough with ResNet [23] was that it is able to train deep neural networks with 150 + layers successfully. Batch Normalization is used at its core. The Batch Normalization adjusts the input layer to increase the performance of the network. The problem of covariate shift is mitigated. Prominent features of ResNet Classifier Model are:

  • ResNet makes use of the Identity Connection.

  • ResNet uses skip connection to add the output from an earlier layer to a later layer. Figure 16 shows plot of loss against Learning Rate, Fig. 17 shows plot of losses.

  • Figure 18 shows plot of losses after selection of LR. Model is trained for ten epoch so error rate is reduced to 3% and there is improvement of 7%.

  • The image classifier is saved as stage 2 model. The images are classified using this stage 2 model. Any particular image is classified as covid or nocovid using these model. Figure 19 shows top losses from ResNet indicating prediction/actual/loss/probability for (10 epoch).

Fig. 16
figure 16

Plot of loss against Learning Rate (ResNet model)

Fig. 17
figure 17

Plot losses (ResNet model)

Fig. 18
figure 18

Plot losses after selection of LR (ResNet model)

Fig. 19
figure 19

Top losses from ResNet model indicating prediction /actual/loss/probability for (10 epoch)

Image Classifier with SqueezeNet

Another type of convolutional neural network [24] which has up to 18 layers is SqueezeNet. It supports training of greater than 1 lakh images. The SqueezeNet model thus has well defined feature extraction. AlexNet is bigger network than SqueezeNet. It has lesser parameters than AlexNet model. It increases the training speed.

Figure 20 shows top losses from SqueezeNet model indicating prediction/actual/loss/probability for (4 epoch) stage 1 of model. SqueezeNet has cluster of fire modules and pooling layers. The squeeze layer decreases the depth to a smaller number, the expand layer increase it. Both have same feature map size.

Fig. 20
figure 20

Top losses from SqueezeNet model indicating prediction /actual/loss/probability for (4 epoch)

Fire module is heart of SqueezeNet, it has two layers: a squeeze layer and an expand layer. Below are the key ideas behind SqueezeNet classifier model:

  • A squeeze layer has at most 1 × 1 filters. Filters are input into an expand layer. It is designed with combination of 1 × 1 and 3 × 3 convolution filters.

  • An input image is first sent into a separate convolutional layer. This layer is tracked by 8 “fire modules”.

  • SqueezeNet performs max-pooling. Figure 21 shows plot of loss against Learning Rate, Fig. 22 shows plot of losses.

  • Activation function is ReLU. To overcome problem of overfitting dropout layers are added, they have probability = 0.5.

  • Deployment process is easier, because it is small in size.

  • The learning rate is decreased during training, at first it is 0.04.

  • Figure 23 shows plot of losses after selection of LR. Model is trained for ten epoch so error rate is reduced to 3% and there is improvement of 7%.

  • The image classifier is saved as stage 2 model. The images are classified using this stage 2 model. Any particular image is classified as covid or nocovid using these model. Figure 24 shows top losses from SqueezeNet indicating prediction /actual/loss/probability for (10 epoch).

Fig. 21
figure 21

Plot of loss against Learning Rate (SqueezeNet model)

Fig. 22
figure 22

Plot losses (SqueezeNet model)

Fig. 23
figure 23

Plot losses after selection of LR (SqueezeNet model)

Fig. 24
figure 24

Top losses from SqueezeNet model indicating prediction/actual/loss/probability for (10 epoch)

Table 1 shows the accuracy percentage of the proposed diagnostic methods (AlexNet, SqueezeNet, ResNet and DenseNet).

Table 1 Comparison of accuracy of the proposed diagnostic methods

Table 2 shows CvDeep accuracy comparison with other deep learning methods.

Table 2 CvDeep accuracy comparison with other deep learning methods

Time and Space Complexity of CvDeep Model

Time complexity of an algorithm measures the extent of time taken by an algorithm to run. It is mathematically represented as a function of the length of the input. As neural network are complex, it is hard to evaluate the complexity of model using them. As the parameters for neural network are application reliant, the execution time for input data is dependent on other algorithms running at the same time. The training time often depends on some parameters passed to the algorithm. Another limitation is that the learning algorithms are complex and dependent on other algorithms.

For algorithms SqueezeNet, DenseNet, ResNet and AlexNet algorithmic complexity depends on number of epoch, size of input data, number of parameters, training time. In this training time may vary. In CvDeep model prediction is whether given image is covid or no covid.

If \(n\) is number of training sample, \(p\) the number of features and \(nli\) the number of neurons at layer \(i\) in a neural network, the following are approximations for time complexity listed in Table 3,

Table 3 Time complexity of CvDeep algorithms

The number of epoch for CvDeep model ranges from 4 to 10, number of parameters vary from methods used, (DenseNet, AlexNet, ResNet and SqueezeNet) size of input data(584 total images). In general time complexity of CvDeep model is approximately \(O(pnl{1}+nl{1}nl{2}+\dots\)).

Space complexity of an algorithm measures the amount of space or memory taken by an algorithm to run with respect to the input size. A typical way to evaluate the performance of an algorithm is by computing the theoretical computational complexity and the memory complexity In CvDeep model, these metrics can be computed at a layer level, where each layer has a theoretical measure of the number of computations that have to be performed and the amount of memory required. Table 4 gives computational and memory complexity of CvDeep algorithms.

Table 4 Computational and memory complexity of CvDeep algorithms

The memory complexity or data volume includes the cost for storing the input feature map or input volume to each layer, the corresponding kernel [25] or filter weights and biases, and the output feature map or output volume. Figure shows the overall time and memory complexity. On the x-axis, individual algorithm name, the left y-axis represents the computational complexity in millions of operations and the right y-axis represents the memory complexity in terms of the number of the data features required to store the input and output feature map and model parameters. For each model, the plot shows the total computational and memory complexity of all the layers in the model. Figure 25 plots computational and memory complexity of all algorithms in CvDeep model.

Fig. 25
figure 25

Computational and memory complexity of all algorithms in CvDeep model

The software implementation and hardware will determine how much of these computations are done in a given amount of time and how much memory is used to do the computations.

Assessment of CvDeep Model Outputs by the Radiologist

Using output of the proposed model (CvDeep) expert radiologists in health centers can confirm their diagnosis. It can reduce time of diagnosis. Outputs of CvDeep model are reviewed by radiologists. Top prediction losses and X-ray data set classification (covid and nocovid) are shared with radiologists.

Reviews of radiologist on model output are:

  • The model has accomplished COVID-19 detection accurately.

  • The model failed to predict for low quality images.

  • The early detection can give immediate help for treatment and thus can control spread of virus.

  • Model must include more images for pneumonia patients.

Conclusions and Future Work

CvDeep model is used to identify and categorize COVID-19 cases. It has achieved accuracy of 95% (ResNet). The model performance is verified by radiologists. Also, it can be used to detect other chest-related diseases with X-rays like tuberculosis and pneumonia. The results of CvDeep model are also compared with other deep CNN models such as COVID-Net, COVIDX-Net and VGG-19 etc. The data set size for COVID-19(+ ve) and COVID-19(− ve) images can be increased in future. It is considered as limitation of this work. The model can be tested for CT images in future. The data set can be shared online to assist radiologists. Patients with COVID-19 (+ ve) can be given instant hospitalization without waiting for lab test result so that survival rate can be increased.