GUNDUA-HLANGANISA: COVID-19 DIAGNOSIS USING ASSEMBLING METHOD FOR IMAGERY

GUNDUA-HLANGANISA: COVID-19 DIAGNOSIS USING ASSEMBLING METHOD FOR IMAGERY

Purposely designed parts

Below our image dataset along with the corresponding directory structure for our project is described, we also discuss the fine-tuning a Convolutional Neural Network to automatically diagnose COVID-19 using Keras, TensorFlow, and deep learning.

tree

├── dataset
│  ├── covid [25 entries]
│  └── normal [25 entries]
├── build_covid_dataset.py
├── sample_kaggle_dataset.py
├── train_covid19.py
├── plot.png
└── covid19.model

Our coronavirus (COVID-19) chest X-ray data is in the dataset/ directory where our two classes of data are separated into covid/ and normal/.

The train_covid19.py script takes advantage of TensorFlow 2.0 and Keras deep learning libraries via a selection of tensorflow.keras imports.

Additionally, we use scikit-learn, the de facto Python library for machine learning, matplotlib for plotting, and OpenCV for loading and preprocessing images in the dataset.

With our imports taken care of, next we parse command line arguments and initialize hyperparameters.
We initialize our initial learning rate, number of training epochs, and batch size hyperparameters.
Next step is to load and preprocess our X-ray data load our data, we grab all paths to images in in the --dataset directory.

Then, for each imagePath, we:
Extract the class label (either covid or normal) from the path.
Load the image, and preprocess it by converting to RGB channel ordering, and resizing it to 224×224 pixels so that it is ready for our Convolutional Neural Network .
Update our data and labels lists respectively.
We then scale pixel intensities to the range [0, 1] and convert both our data and labels to NumPy array format.

Next we will one-hot encode our labels and create our training/testing splits.
Each encoded label consists of a two element array with one of the elements being “hot” (i.e., 1) versus “not” (i.e., 0).

We then construct our data split, reserving 80% of the data for training and 20% for testing.

In order to ensure that our model generalizes, we perform data augmentation by setting the random image rotation setting to 15 degrees clockwise or counterclockwise.

We will initialize our VGGNet model and set it up for fine-tuning.
The VGG16 network is instantiate with weights pre-trained on ImageNet, leaving off the FC layer head.
From there, we construct a new fully-connected layer head consisting of POOL => FC = SOFTMAX layers and append it on top of VGG16.

We then freeze the CONV weights of VGG16 such that only the FC layer head will be trained; this completes our fine-tuning setup.

We’re in a position to compile and train our COVID-19 (coronavirus) deep learning model.

We compile the network with learning rate decay and the Adam optimizer. Given that this is a 2-class problem, we use "binary_crossentropy" loss rather than categorical crossentropy.

To kick off our COVID-19 neural network training process, we make a call to Keras’ fit_generator method, while passing in our chest X-ray data via our data augmentation object.

For evaluation, we first make predictions on the testing set and grab the prediction indices.
We then generate and print out a classification report using scikit-learn’s helper utility.

Then, we generate a confusion matrix. Use the confusion matrix to derive the accuracy, sensitivity, and specificity and print each of these metrics. We then plot our training accuracy/loss history for inspection, outputting the plot to an image file.

Finally we serialize our tf.keras COVID-19 classifier model to disk.