1 Introduction

Severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) is a novel virus that is enveloped with a large, single-stranded RNA genome. It emerged in Wuhan, China in December 2019 and caused the greatest pandemic of the millennium [1]. According to the World Health Organization (WHO) report, the total number of people infected by the disease as of 27 July 2020 is 16,114,449 with 646,641 deaths. The typical symptoms of the disease are fever, breathlessness, cough, fatigue, and loss of taste and smell [2]. The standard method for diagnosing COVID-19 is reverse transcription-polymerase chain reaction from a nasopharyngeal swab. Even though the continuous polymerase chain reaction examination of the sputum has the best quality for detecting COVID-19, the time required to confirm COVID-19 in infected patients can be high given the elevated false positive results of the examination [3]. Therefore, clinical imaging modalities, for example, chest X-ray (CXR), can play an important role in diagnosing individuals where there is a high doubt of infection according to symptoms and hazard factors, with the exception of pregnant women and children outside of emergency situations [4]. CXR images have been explored in the ongoing pandemic for detecting COVID-19.

Chest computed tomography (CT) imaging may likewise aid in the diagnosis of COVID-19; however, current guidelines do not suggest utilizing CT imaging for routine screening. Hence radiologists recommend CXR for the diagnosis of COVID-19. The advantage of X-ray machines is that most radiological laboratories and hospitals are capable of acquiring 2-dimensional projection images of the patient’s chest. In general, CXR images play a vital role for radiologists in perceiving the chest pathology and have been applied in the confirmation or recommendation of COVID-19 in infected patients [5]. Figure 1a, b, and c show sample CXR images of a normal, COVID-19, and pneumonia patient, respectively [6].

Fig. 1
figure 1

Sample CXR images a Normal b COVID-19 c Pneumonia

Computer-aided diagnosis (CAD) frameworks assist with a rapid, automatic diagnosis using graphical processing units (GPUs) by processing medical images. To the best of our knowledge, deep learning (DL) architecture has been used in many CAD frameworks and in numerous medical imaging applications, such as for COVID-19 [7]. In recent years, the convolutional neural network (CNN) has yielded the most promising results in classifying radiological images. CNNs are DL algorithms and have been used in many applications, including image classification. These advantages motivated our attempt to propose a CNN algorithm for COVID-19 diagnosis in this paper.

The hyperparameters of CNNs have an important influence on the network’s performance, as they directly control the training process. The selection of appropriate hyperparameters plays a vital role in the training of the CNN network. For example, if the learning rate is too low, the network may lose important details in the data. By contrast, if the learning rate is too high, it may lead the model to converge too quickly. Therefore, there is a need to optimize the hyperparameters of CNNs for proper training and optimum performance results.

The novelty of this work is twofold. First, we optimized the hyperparameters of a CNN using the Grey Wolf Optimization algorithm according to CXR images. In addition, the proposed method avoids the overfitting of input images and real-time images with better performance metrics.

The details of the contributions are as follows:

  1. I.

    Hyperparameters of the CNN are optimized using Grey Wolf Optimization to determine the best accurate results in diagnosing COVID-19, normal, and pneumonia patients from CXR images.

  2. II.

    Grey Wolf Optimization is compared with other optimization algorithms for tuning the CNN’s hyperparameters.

  3. III.

    A CNN model is proposed for the automatic diagnosis of COVID-19 using CXR images with an accuracy of 97.78%.

The rest of this paper is arranged as follows: Related works are introduced in Section 2. The theoretical and mathematical fundamentals are given in Section 3. The material and methodology are presented in Section 4. The experiments are given in Section 5. Finally, the conclusion is presented in Section 6.

2 Related works

Recently, AI-based techniques for identifying and tracing COVID-19 have been popular in the global attempt to end the pandemic. This section briefly covers ongoing attempts at determining a COVID-19 diagnosis utilizing CXR images. Since uncovering the possibility of using CXR images in recognizing COVID-19 and the shortcomings of manual detection, there have been a number of investigations attempting to create automatic COVID-19 classification frameworks, mainly utilizing CNNs. Narin et al. [8] introduced a study of three distinctive CNN models, including InceptionV3, ResNet50, and Inception-ResNetV2, that were proposed for the recognition of COVID-19 utilizing CXR images.

Hemdan et al. [9] presented COVIDX-Net, which incorporates seven unique designs of deep convolutional neural network (DCNN) including an improved VGG19 and the second form of Google MobileNet. Each DCNN model can inspect the normalized forces in CXR images to portray the patient status as either negative or positive COVID-19. The DenseNet and VGG19 models were capable of automatically detecting COVID-19. Khan et al. [10] proposed CoroNet, a DCNN model, to perform image processing on X-ray images and classify them positively or negatively. Li et al. [11] demonstrated a mobile-based lightweight DL network architecture, namely, COVID-MobileXpert.

Maghdid et al. [12] proposed an AI model for radiologists and health experts to analyze COVID-19 cases quickly and accurately. This involved constructing an extensive dataset of CXR and CT images from various sources and developed a necessary yet compelling COVID-19 identification procedure utilizing DL and TL techniques. Mahdy et al. [13] introduced a strategy for identifying COVID-19-infected persons utilizing CXR images. Multilevel thresholding and a support vector machine (SVM) were introduced to achieve high accuracy with images of the infected lungs of COVID-19 patients. Rehman et al. [14] utilized pretrained information to improve demonstrative execution using TL methods and performed a comparative analysis with different CNN structures.

Abbas et al. [15] validated and adapted their recently created Decompose, Transfer, and Compose (DeTraC) CNN for the diagnosis of COVID-19 with CXR images. DeTraC can manage any anomalies in the image dataset by researching its class limits utilizing a class disintegration system. The TL was used for tweaking the parameters.

Afshar et al. [16] introduced an elective demonstrating system dependent on capsule networks (rather than CNNs), alluded to as the COVID-CAPS, which was equipped to work with small datasets vitally because of the abrupt and fast development of COVID-19. Apostolopoulos et al. (2020) [17] depicted a method to assess the performance of best-in-class CNN models proposed over recent years for clinical image classification. More specifically, a methodology called TL was employed in their work.

Apostolopoulos et al. (2020) [18] additionally introduced the best-in-class CNN called Mobile Net. This was utilized and developed without any preparation to research the significance of the extricated features for the characterization of COVID-19. Farook et al. [19] built open source datasets for COVID-19. They introduced an exact CNN structure for separating COVID-19 from pneumonia cases. This work utilized the best training techniques, including dynamic resizing, TL, and discriminative learning, to train the CNN quickly and accurately using DL frameworks.

All the techniques on DL–based COVID-19 screening have so far used CNNs, which, despite their incredible image handling capability, are unable to identify the unique relations between image examples. Because of this disadvantage, CNNs cannot perceive items as similar when one has been rotated or subject to another sort of change. As a result, CNNs require large datasets, including all possible changes to which images can be subjected. Nonetheless, in clinical imaging settings, including COVID-19 screening, large datasets are most certainly not adequately available. The proposed Optimized Convolutional Neural Network (OptCoNet) is an alternative model capable of screening COVID-19 without a vast dataset since it captures spatial information coming from instances and object parts using potential changes in the existence of the objects.

3 Grey wolf optimizer

The Grey Wolf Optimizer (GWO) [20], a recently developed swarm intelligence (SI) algorithm, has proven to be a reliable optimization algorithm compared to conventional evolutionary and swarm-based algorithms. The gray wolf belongs to the Canidae family. It is considered a high-level predator and dwells at the top of the food chain. They live in a pack that comprises 5–12 wolves on the whole. In gatherings, an exact predominance order is maintained. The pack is driven by alphas and trailed by betas, the subordinate wolves who are mindful to help the alpha in maintaining the dynamics of the pack.

The beta wolf strengthens the alpha’s orders all through the pack and offers input to the alpha. In the interim, the lowest rung among the gray wolves is the omega, who generally assumes the scapegoat’s job. They are the last wolves allowed to eat from the prey. On the off chance that a wolf is not alpha, beta, or omega, the individual in question is known as a delta. Delta wolves act as scouts, sentinels, seniors, trackers, and guardians.

The motivation for proposing the GWO algorithm for COVID-19 diagnosis is twofold. First, it is a very competitive optimization algorithm. It has been applied to various research fields, such as feature selection, economic load dispatch problems, and flow scheduling problems. In addition, the GWO algorithm benefits from avoiding high local optima, which leads to avoidance of overlapping features in the problem of feature selection.

The main mechanisms of GWO, including social pecking order, following, circling, and attacking prey, are introduced as follows.

In the GWO algorithm, the fittest solution can be represented as the alpha (α), with the second and third-best solutions represented as beta (β) and delta (δ), respectively. The remainder of the up-and-coming solutions are considered omegas (ω). GWO uses these simple principles to rank the solutions in each iteration and update their positions.

When wolves hunt, they will, in general, enclose their prey. The following mathematical equations delineate this encircling behavior

$$ \mathrm{D}=\mid \mathrm{C}.{\mathrm{X}}_{\mathrm{p}}\left(\mathrm{t}\right)-\mathrm{X}\left(\mathrm{t}\right)\mid $$
(1)
$$ \mathrm{X}\left(\mathrm{t}+1\right)={\mathrm{X}}_{\mathrm{p}}-\mathrm{A}.\mathrm{D} $$
(2)

where D denotes distance, t represents the present iteration, A and C are coefficients, Xp is the prey’s location, and X denotes the position of a gray wolf.

The coefficients A and C are calculated as follows:

$$ A=2 ar1-a $$
(3)
$$ C=2r2 $$
(4)

where r1 and r2 are random values between 0 and 1 and ‘a’ is a decreasing parameter.

As mentioned above, the three best solutions (alpha, beta, and delta) are updated first, and then, the other search agents (omega wolves) update their positions, all using the following equations:

$$ \mathrm{D}\upalpha =\mid \mathrm{C}1\mathrm{X}\upalpha -\mathrm{X}\mid, \mathrm{D}\upbeta =\mid \mathrm{C}1\mathrm{X}\upbeta -\mathrm{X}\mid, \mathrm{D}\updelta =\mid \mathrm{C}1\mathrm{X}\upalpha -\mathrm{X}\mid $$
(5)
$$ X1= X\alpha -A1.\left( D\alpha \right),X2= X\beta -A1.\left( D\beta \right),X1= X\delta -A1.\left( D\delta \right) $$
(6)
$$ \mathrm{X}\left(\mathrm{t}+1\right)=\frac{X_{1+}+{X}_{2+}{X}_3}{3} $$
(7)

To summarize, the optimization approach for GWO commence with making an arbitrary populace of grey wolves, which can be called applicants of solution. During the recreation, alpha, beta, and delta wolves gauge the conceivable situation of the prey. The parameter of ‘a’ in Eq. (3) can be demonstrated as investigation and abuse forms by diminishing the incentive from 2 to 0. Up-and-comer arrangements have separated from the prey if |A| > 1 and converged toward the prey |A| < 1. The GWO algorithm iteratively updates and evaluation candidate solutions until an end condition is met.

To summarize, the optimization approach for GWO begins with making an arbitrary populace of gray wolves, which can be called applicants of solution. During recreation, alpha, beta, and delta wolves gauge the conceivable situations of the prey. The parameter ‘a’ in Eq. (3) can represent investigation or abuse by decreasing the value from 2 to 0. Up-and-comer solutions indicate distancing from the prey if |A| > 1 and convergence toward the prey if |A| < 1. The GWO algorithm iteratively updates and evaluates candidate solutions until an end condition is met.

4 Materials and methodology

4.1 Dataset

CXR images of COVID-19, normal, and pneumonia patients collected from publicly available repositories [21,22,23,24,25,26] were used in this work. These repositories yielded a total of 2700 images, out of which 900 were COVID-19 images. The resolution of all images was set to 224x224x3 pixel size. The details of the images are stated in Table 1.

Table 1 Dataset used in this study

4.2 Workflow

A CNN is a type of DL model that extends the capability of the artificial neural network (ANN) by adding more layers to its architecture. CNNs have excellent feature extraction, pattern recognition, and classification performance of the raw input data without any preprocessing. The CNN architecture is divided into two parts: feature extraction and classification. Feature extraction is performed using several layers, including a convolutional layer (CL) followed by a max-pooling layer (MPL). Classification consists of a fully connected layer (FCL) and a classification layer to classify the input features into a particular class. CLs and FCLs are composed of weights and biases, which should be tuned using a gradient descent training algorithm. The training algorithm should also include many hyperparameters, which strongly reflect the CNN model’s performance. These parameters are the training algorithm, momentum, learning rate, number of epochs, validation frequency, and L2Regularization. The current work is focused on optimizing these hyperparameters for training the CNN to yield optimal performance results. Although hyperparameters are very important for producing better performance, testing each hyperparameter is computationally expensive. Therefore, GWO is proposed in this architecture to optimize the hyperparameters for training the layers of the CNN. Figure 2 shows the flow diagram of the proposed network of hyperparameter optimization for a CNN using GWO. The description of the proposed model is discussed as follows.

Fig. 2
figure 2

Flow diagram of grey wolf optimized CNN for COVID-19 diagnosis

4.3 Convolutional neural network

The CNN architecture is composed of an input layer, CL, MPL, FCL, and output layer. The CL layer of the CNN is responsible for extracting features from the input images using several convolutional filters. These convolutional filters perform the convolutional operation at every offset of the input image. The CL contains weights that should be optimized using gradient descent training, which adjusts the parameters of the CL. The features extracted from the CL are mapped into feature space using a nonlinear rectified linear unit (ReLU) activation function. A batch normalization layer (BNL) is used between the CL and ReLU to normalize the gradients and activations through the network. The PL is used to reduce the dimensions of the feature maps obtained from the CL and retain the most relevant information of the image. Pooling methods include max-pooling and average pooling. There are no weights or biases in the PL of the CNN to train. The last layer is a fully connected classifier layer that classifies the extracted features from the CL and MPL into a particular class.

CNN training involves adjusting the parameters of the convolutional kernels and hidden neurons in the fully connected classification layer. Generally, CNNs utilize stochastic gradient descent (SGD) training to tune the CL and fully connected layer parameters. SGD minimizes the cost function by updating the weights of the network in the backward direction.

The disadvantage of using SGD is that it contains many hyperparameters that influence the network’s performance. The next section explains the algorithm used to optimize these hyperparameters to achieve the best network performance. Details of the layers of the proposed CNN are given in Table 2.

Table 2 Architecture of proposed CNN

4.4 Hyperparameter optimization using GWO

In this work, the hyperparameters are optimized using GWO. Hyperparameters play a crucial role in determining the accuracy and convergence of the CNN. Selecting the network’s hyperparameters is essential and depends on the application for which the CNN is used. The learning rate, number of epochs, momentum, and regularization coefficient are the most common CNN training hyperparameters. The learning rate controls the gradient descent algorithm’s speed, and the momentum controls the influence of the update of previous weights on the update of current weights. The number of epochs determines the number of times the learning algorithm will update the network parameters according to the training dataset. Regularization overcomes the issue of overfitting in the network. Therefore, to address all these settings, optimizing these hyperparameters is required to help the network yield the most accurate results. The GWO algorithm for the optimization of hyperparameters in SGD training is given in Algorithm (1).

figure e

5 Experiments

To benchmark the performance of the proposed GWO-based CNN for COVID-19, normal, and pneumonia images, tests were conducted for classification using different optimization techniques.

5.1 Implementation details

The algorithm was implemented in MATLAB 2020a and executed using Windows 10 Pro with a 64 GB RAM Nvidia GPU. The proposed architecture was tested for both normal, phenomena, and COVID-19 CXR images using publicly available datasets.

5.1.1 Training

For the diagnosis of COVID-19 from CXR images, a six CL CNN is used. The A total of 70% of the data are used for training, and the remaining 30% of the data are used for testing the network. The proposed architecture classifies images into three categories: normal, pneumonia, and COVID-19. The dataset is partitioned randomly into training and test sets. All the images are resized to 224x224x3 using data augmentation and converted to color images. A six convolutional layer architecture is used to classify the images, and parameters are tuned using SGD training, whose hyperparameters are optimized using GWO at the time of training. The optimized hyperparameters obtained using GWO optimization are given in Table 3, and sample training images are provided in Fig. 3.

Table 3 Training options using GWO optimization
Fig. 3
figure 3

Sample training images a-b COVID-19 c-d Normal e-f Pneumonia

5.1.2 Testing

First, the images are resized to 224x224x3 using data augmentation and training the proposed network. After that, the test images are given as input to the trained CNN, where all the parameters of the CLs and FCLs are already optimized. Then, the CNN first extracts the images features and classifies them into the appropriate class using FCL and soft-max classifiers. The sample testing images are given in Fig. 4.

Fig. 4
figure 4

Sample testing images a-b COVID-19 c-d Normal e-f Pneumonia

5.2 Performance indicators and evaluation metrics

This subsection presents the proposed methodology’s performance in classifying the images into COVID-19, normal, and pneumonia. The proposed method is validated using the performance metrics of accuracy, sensitivity, specificity, precision, and F1-score, and receiver operating characteristic (ROC) analysis will be used for verifying the results from actual cases. The performance metrics equations are summarized in Table 4.

Table 4 Performance measures for COVID-19

where TP indicate True Positive; TN indicate True Negative; FP indicate False Positive; FN indicate False Negative.

Accuracy evaluates the ability of the classifier to differentiate between COVID-19 and non–COVID-19 cases. A TP is where the model adequately predicts a positive case. Therefore, a TN is where the model viably predicts a negative instance. An FP is where the model erroneously predicts a positive case, and an FN is where the model mistakenly predicts a negative situation. Sensitivity gauges the proportion of correctly classified positive instances. Specificity is a measure of the correctly classified negative instances. Precision measures the fraction of relevant cases among the retrieved cases and is also known as the positive predictive value. The F1-score measures a test’s accuracy and is defined as the weighted harmonic mean of the test’s precision and recall. The receiver operating characteristic (ROC) curve is the characteristic representation of the classification method performance executed for all values. This curve is drawn as the relationship between 1-specificity and sensitivity.

5.3 Experimental results

In this paper, CXR images are used to diagnose COVID-19 from normal and pneumonia-infected persons. X-ray imaging is a noninvasive technique for diagnosis and is also available in most hospitals. Using the trained proposed optimized CNN, testing of the images will take less than 5 s. The proposed network results are given in Table 5, which shows that an accuracy of 97.78% is achieved.

Table 5 Experimental results of the proposed network model

5.3.1 Receiver operating characteristics (ROC) and confusion matrix

The ROC curve (in Fig. 5) and confusion matrix (in Fig. 6) were generated for the proposed method to analyze the classification effectiveness. Following application of the proposed methodology for 2700 chest X-ray images, 98.5% were classified as COVID-19, 97.4% were classified as normal images and 97.4% were classified as pneumonia images. The proposed method has high accuracy for all three cases. Hence, this OptCoNet can be used for automatic screening of COVID-19. This OptCoNet will substantially help radiologists by overcoming the burden on the healthcare system.

Fig. 5
figure 5

Generated ROC curves of the proposed GWO optimized CNN (Class 1-COVID-19, Class 2- Normal, Class 3-Pneumonia)

Fig. 6
figure 6

Generated confusion matrix from the GWO optimized CNN

5.3.2 Training progress of the proposed OptCoNet

As the selection of hyperparameters in training the CNN plays an important role, this subsection presents the results of an experiment comparing the training progress and loss functions between the GWO-optimized and nonoptimized CNNs. The training progress of the optimized and nonoptimized CNNs is shown in Fig. 7a and b, respectively. The proposed OptCoNet achieves better accuracy and minimum loss in all epochs. The training parameters of the optimized GWO are described in Table 6.

Fig. 7
figure 7

Training progress for the (a) GWO-optimized (a) Nonoptimized CNNs

Table 6 Parameters of GWO

5.4 Performance analysis

In this work, five standard optimization techniques other than GWO are used in the classification of images. These are Genetic Algorithm (GA) [27], Pattern Search (PS) [28], Particle Swarm Optimization (PSO) [29], Simulated Annealing (SA) [30], and Whale Optimization Algorithm (WOA) [31]. For training the DL networks, 70% of the data are used; the remaining 30% of the data are used for testing. A comparison of all these networks in terms of the metrics accuracy, specificity, sensitivity, precision, and F1-score is given in Table 7. Comparisons in terms of ROC curves and confusion matrixes are illustrated in Figs. 8 and 9. The results of these comparisons indicates that the CNN optimized by GWO provides the best accuracy. Therefore, the proposed network can be reliably used to diagnose COVID-19 in real-time applications.

Table 7 Performance analysis with other optimization methods
Fig. 8
figure 8

ROC curves of the a GWO b GA c PS d PSO e SA and f WOA-optimized CNNs (Class 1-COVID-19, Class 2- Normal, Class 3-Pneumonia)

Fig. 9
figure 9

Confusion matrixes of the a GWO b GA c Pattern search d PSO, e Stimulated annealing, and f WOA-optimized CNNs

5.5 Comparative analysis

This subsection presents a comparative analysis for the proposed methodology in classifying the images into COVID-19, normal, and pneumonia. Comparisons are made with other state-of-the-art methods using the aforementioned performance metrics. A discussion and limitations of the proposed work are given at the end of this subsection as well.

5.5.1 Comparison with nonoptimized CNN

Figures 10 and 11 show the performance comparison in terms of the ROC curves and confusion matrixes between the optimized and nonoptimized CNNs. From Figs. 10 and 11, the optimized CNN yields a better accuracy than the nonoptimized CNN.

Fig. 10
figure 10

Generated ROC curves for the a GWO-optimized CNN and b Nonoptimized CNNs (Class 1-COVID-19, Class 2- Normal, Class 3-Pneumonia)

Fig. 11
figure 11

Confusion matrixes for the a GWO-optimized CNN and b Nonoptimized CNN

5.5.2 Comparison using cross-validation

Cross-validation (CV) is an important tool in predicting network performance by splitting the data k times into training and testing sets. In the present work, k is set to 10. Therefore, the X-ray data of each class are split into ten subsets. For every iteration of the CV, one subset from the k subsets is used for testing, and the remaining k-1 subsets are used for training the network. Then, the error rate is calculated k times for the proposed optimized nonoptimized CNN. A comparison of the CV results is shown in Fig. 12.

Fig. 12
figure 12

Comparison with cross-validation

5.5.3 Comparison with grid search optimization

The conventional method for optimizing the hyperparameters of a neural network is the grid search strategy (GSS) [32]. In the GSS, a subset of each hyperparameter space is manually specified and evaluated for a particular performance metric. The GSS evaluates the network performance by making a grid of all possible candidates within the hyperparameter space. The combination of hyperparameters that yields the best performance metric will be selected as the optimized hyperparameter values. The main drawback of the GSS is the exponential increase in the number of evaluations as a new parameter is added. Therefore, with only four hyperparameters with five candidates for each, the number of iterations is 758, making this optimization impractical.

On the other hand, GWO uses random values for the parameters and stops according to prespecified stopping criteria such as maximum time, number of parameters, or performance goal. In this way, it avoids overfitting the data and is practical for real-time problems with good performance results. The accuracy comparison of GWO with GSS is shown in Fig. 13.

Fig. 13
figure 13

Comparison of GWO with GSS

5.5.4 Comparison with different CNN architectures

An experiment was conducted to compare the proposed OptCoNet architecture with other nonoptimized CNN architectures, namely, network2, network3, network4, and network5. The proposed OptCoNet provides better accuracy than the other CNN architectures. The results and the developed architectures are found in Figs. 14 and 15, respectively.

Fig. 14
figure 14

Comparison with different CNNs

Fig. 15
figure 15

Architecture information of different CNNs a OptCoNet b Network2 c Network3 d Network4 e Network5

5.5.5 Comparisons of the results with state-of-the-art CNN methods

For further analysis of the results, the performance metrics, such as accuracy, sensitivity, specificity, precision, and F1-score, are also compared between the proposed CNN and pretrained DL networks. The acquired performance parameters for the proposed CNN are better than those of other state-of-the-art approaches, as shown in Table 8. The advantage of the proposed method is that no settings are required while training the images. Consequently, no tuning is needed for different databases, as opposed to other model-based methodologies, as in [8, 14]. In this way, the proposed approach can successfully deal with any concealed databases with no particular parameter tuning. The specialists in [8, 14, 32] accomplished a marginally poorer accuracy with their DLs compared to the proposed OptCoNet because of the absence of primary data in the images. Likewise, the proposed method is compared with recently published works in terms of the accuracy and F1-score. The proposed approach produced better results than other state-of-the-art techniques.

Table 8 Comparison of the results with state of the art CNN methods using X-ray images

5.6 Discussion

Given how COVID-19 has infected millions of people worldwide, there is a need for quick and accurate diagnosis of the disease. The proposed network can discriminate COVID-19 patients from normal and pneumonia patients using X-ray images. X-ray image diagnosis is a noninvasive, cost-effective technique that is available in almost all hospitals. The proposed optimized CNN network was trained using 1890 images and then tested on 810 images. It provides an accuracy of 97.78%, which is the best accuracy achieved on X-ray images to date with more number of images. The optimized CNN was compared with state-of-the-art optimization techniques and four other CNN to show its efficiency. The advantages of the proposed optimized CNN include its ability to directly give diagnostics results from X-ray images without the need of a radiologist. In this way, it can help clinicians test patients with accurate results quickly. There is no need to preprocess the test images; the data augmentation step will resize all the test images to 224 × 224 pixels. Finally, the CNN hyperparameters are optimized using the GWO algorithm on X-ray images to avoid the problem of overfitting and mode collapse and give the best performance results.

Similar to any other new methods, the proposed method also has some limitations. One of the limitations is that the proposed OptCoNet does not encode the position orientation of the input images, so some preprocessing steps are required. In addition, OptCoNet is not spatially invariant to the input images. Finally, GWO has a number of controlling parameters that need to be carefully chosen if applied to problems with an extremely large number of features and parameters.

6 Conclusions

This work proposes OptCoNet, which depends on an optimized CNN structure for the automatic diagnosis of COVID-19, normal, and pneumonia patients from X-ray images. This system comprises a number of convolutional, batch normalization, and pooling layers. The acquired outcomes show that the OptCoNet performed well, even with a low number of trainable parameters. The proposed OptCoNet produced better performance metrics such as accuracy, sensitivity, specificity, precision, and F1-score than current state-of-the-art methods. As increasingly more COVID-19 cases are being recognized all around the globe, larger datasets are being created. Future studies will focus on advancing and altering the architecture of the OptCoNet and fusing newly accessible datasets to test the network.