Covid-19 Diagnosis using Radiography Images

Vivek Maskara
Jul 25, 2020 · 3 min read
Image for post
Image for post
Source: Covid-19 Radiography Dataset [1]

In this post, we will try to classify images from the Covid-19 Radiography Dataset[1] using a pre-trained ResNet-18 network. We will be using the PyTorch library for building our network.

Disclaimer: This model should be used only for learning purposes as Covid-19 diagnosis is an ongoing research topic.

Download the dataset

Data preprocessing

Also, we are defining a transformer to Resize the images to 224x224 px and then converting the image to a Tensor.

Next, we. split the dataset into training, validation, and testing sets. We would be using 20% of the data for testing and 10% of the data for validation using a SubsetRandomSampler.

Next, let us define the DataLoader for training, testing, and validation sets.

Now, that our DataLoader is defined, let us use the train_loader to visualize a few images along with their classes.

Image for post
Image for post

Defining the model

Let’s add fully connected layers at the end of the network, to adjust the final layer’s output to correspond to the number of classes in our dataset.

We would be using CrossEntropyLoss as the loss function and a learning rate of 3e-5 for training.

Training

Epoch: 1  Training Loss: 0.569099  Validation Loss: 0.045166 Validation loss decreased (inf --> 0.045166).  Saving model ... Epoch: 2  Training Loss: 0.447157  Validation Loss: 0.035986 . 
.
.
.
Epoch: 19 Training Loss: 0.229328 Validation Loss: 0.016049 Epoch: 20 Training Loss: 0.248973 Validation Loss: 0.013585 Validation loss decreased (0.014983 --> 0.013585). Saving model ...

Evaluation

Test Loss: 0.037036 
Test Accuracy of COVID-19: 100% (48/48)
Test Accuracy of NORMAL: 97% (268/276)
Test Accuracy of Viral Pneumonia: 91% (233/256)
Test Accuracy (Overall): 94% (549/580)

Conclusion

References

Originally published at https://www.maskaravivek.com on July 25, 2020.

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data…

Sign up for Analytics Vidhya News Bytes

By Analytics Vidhya

Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Vivek Maskara

Written by

Grad Student at ASU | Student Researcher at The Luminosity Lab | Ex Senior Software Engineer, Zeta | Volunteer, Wikimedia Foundation

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Vivek Maskara

Written by

Grad Student at ASU | Student Researcher at The Luminosity Lab | Ex Senior Software Engineer, Zeta | Volunteer, Wikimedia Foundation

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store