Humans around the globe are in panic and suffering from the pandemic of the 21st century i.e COVID 19 – the word itself speaks everything.
Governments are locking down countries, but daily the number of infected patients continues to rise. As on May 20, 2020 while writing this blog, currently there are more than 4.89 million cases across the world.
Image Credit – https://coronavirus.jhu.edu/data#charts
So this blog explores how machine learning (ML) can play a wide role during this pandemic situation by helping the doctors and society in general to detect such viruses conditions..
Yeahh, it’s possible !!
A machine can detect covid patients from x-rays on the basis of some hefty algorithms and trained models !!
Excited ? Let’s see how all it works.
How it works !
If you have a good amount of labelled data ( dataset ), then that is the key for solving the problems using machine learning.
In our case, we are going to use an X-ray dataset of the patients who were reported as COVID positive and negative.
Unfortunately, currently, COVID-19 lung scan datasets are limited. So we had referred to one of the good collections of COVID-19 open-source dataset. It consists of x-ray images made available publically for research use. Once we have a filtered dataset, we can train a model on a large number of COVID positive v/s COVID negative x rays images, using appropriate algorithms, and then use that algorithm to detect COVID from the input x rays.
This is how Artificial Intelligence (AI) can detect the COVID-19 from the images.
Confused? Let’s move closer to the actual process.
How can trained models detect COVID-19 from just an image ?
To train a model accurately, we should have a filtered x-ray dataset, with proper balanced images,
for example :
- 100 x-ray images ( Covid Positive )
- 100 x-ray images ( Covid Negative )
Once we have a filtered dataset, we can train the model using the hefty libraries of python like tensorflow and keras.
Steps for training Covid-19 detection model
- Installing the required libraries
1234pip install tensorflowpip install opencv-pythonpip install numpypip install argparse
- Extract the class labels ( either Covid or Normal )
12345678910111213141516171819202122pip install tensorflowimagePaths = list(paths.list_images(args["dataset"]))data = labels = for i in imagePaths:# extracting the class label from the filename ( Covid or Normal)label = i.split(os.path.sep)[-2]# loading the image, converting it to RGB, resizing it to 224x224image = cv2.imread(i)image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)image = cv2.resize(image, (224, 224))# updating the data and labels,data.append(image)labels.append(label)# converting the data and labels to NumPy arraysdata = np.array(data) / 255.0labels = np.array(labels)
- Loading the image and converting it to RGB channel and resizing it as per the need , in our scenarios 224*224 pixels as shown above, to make it ready for the Convolutional Neural Network.
- Initialize VGGNET model and set it up for fine tuning.
- Compiling the network with Adam optimizer , and using binary_crossentropy loss as it is a 2-class problem, rather than using categorical crossentropy.
- And in the end to follow some basic rules and algorithms of training a model.
These were few overall steps to train a model, for entire code stay tuned at our github repository.
After passing through all such processes of training, in the end we will have a trained model ( Prediction Model ), which will be able to discriminate between the x-ray of covid patients and of normal patients.
Trained model is the kind of brain made using machine learning.
AI based Covid-19 detection
In addition , we have made a model which can detect whether the uploaded image is an x-ray image or not.
So it can be helpful during the training process, as if a doctor or user uploads a non x-ray image in a dataset during a new training process, then the algorithm will throw out that image and will take only x-ray images into consideration for training of the model.
” Yeahh, machine is brilliant if it is trained well like humans .”
Covid-19 detection using Artificial Intelligence
Above is the demonstration of detecting COVID-19 from the input x-rays, using the trained model and image classification algorithms. It can detect whether the x-ray belongs to the covid patient or normal patient.
X-ray detection using pre-trained model
Above is the demo of detecting the x-rays from thousands of images using trained models on x-rays, and storing those detected images in an x-ray named folder for training use.
So, in conclusion we can say,
“In a list of all superheroes like doctors, cops, covid workers, Artificial Intelligence will be playing its role soon.”