How You Can Apply Deep Learning on Covid-19 Image-Dataset: Beginner Guide
Introduction
Due to the Coronavirus, most of the students, deep learning enthusiasts are in lockdown. So, for them in this post, I will try to explain How coronavirus works in our body (just a high-level overview), What is the need of this classifier in today’s world, and at last, we will cover Some deep learning concept and code to build this classifier so that you can make your own classifier.
Disclaimer: The method and technique which I used in this post are meant for educational purposes only. This is not a scientific study. this is just an article for the learners who are interested in deep learning. I kindly ask that you treat it as such.
Part I: How Covid19 Works in Our Body?
COVID-19 is a disease that can cause what doctors call a respiratory tract infection. It can affect your upper respiratory tract (sinuses, nose, and throat) or lower respiratory tract (windpipe and lungs). It’s caused by a coronavirus named SARS-CoV-2.
It spreads the same way other coronaviruses do, mainly through person-to-person contact. Once the virus enters it causes discomfort when it reaches the air passages on the outside of the lungs and injures the lining of the passageways, and the body responds with an inflammation, which in turn irritates the nerves in the lining. That is when an infected person coughs.
If the virus goes past the lining of the airways and reaches the air sacs at the end of the air passages called alveoli, these sacs are responsible for the exchange of gas in the lungs.if they get infected, the sacs respond with inflammatory fluids, which fill the air sacs.
That is what leads to pneumonia (when the lungs’ ability to transfer oxygen is impaired and the infected person has difficulty breathing). When a person cannot inhale enough oxygen and exhale enough carbon dioxide, pneumonia can lead to death. you can get more information here
Part II: What is the need for an Image Classifier?
There are different types of coronavirus tests that can be done:
- Swab Test — In this case, a special swab is used to take a sample from your nose or throat
- Nasal aspirate — In this case, a saline solution will be injected into your nose and, then a sample is taken with a light suction
- Blood test — In this case, a blood sample is taken from a vein in the arm.
These tests are Costly in many countries like in India it will cost you about 4500 and probably you have heard the news like “Hospitals are forcing patients to undergo repeated tests before discharging them,” and they take approx 5 hrs per patient.
So that’s we need X-ray or CT Scans in the current situation.
But X-ray or CT Scans also has it’s limitation like they have large and complex pieces of machinery. They need to be thoroughly cleaned between each potential COVID-19 patient.
Part III: How You can make your own Image classifier?
So, these are five steps for making this Image Classifier are
a)Import the libraries, dataset and split the dataset into train and validation
We import libraries like pandas, NumPy, and torch.we will use these libraries like pandas for showing the result, NumPy for computation,matplotlib, and seaborn for showing the result, torch and torchvision to obtain pre-trained model, nn and OrderDict for making our own classifier.
Then we import the dataset and specify the train directory and validation directory in which our images are kept.
b)Some transformation for a better result in training and testing data.
We specify transformation like Rotation, Cropping, Flip, for training the model then we load the different datasets into different loaders like train loader and validation loader.
c)Loading the pre-trained model and changing its classifier for 2 categories only.
We import the densenet161 pre-trained model for image classification. This is the good pre-trained model for this particular case. I have tried many models this model gives the best accuracy.
Then we define our own classification layer I have used 10 layers for classification but if you want then you use as many layers as you want.we will just train classifier not the full model so, I set the gradient of the whole model to false except classifier.
d)Sending Images for training.
we pass our whole image dataset 20 times. then we are calculating loss and using backpropagation improving the weights for better prediction.
e)Testing for validation.
We just forward pass the image and After running all the cells I get accuracy more than 98%.if you want to refer to the here is the full code.
Conclusion
In this article, we look at how you can apply deep learning on the coronavirus image dataset.
- We look at how coronavirus enters our body, the parts coronavirus damages and it further leads a healthy person to death.
- We look at the different types of tests like a blood test, swab test and we discuss the need for this image classifier.
- We look at deep learning concepts like transfer learning and implemented then using PyTorch and obtain an accuracy of 98%.