Git Product home page Git Product logo

lopez-christian / covid-19-pytorch-image-classifier Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 8.51 MB

This repository includes my COVID-19 PyTorch Image Classifier-Flatiron School Capstone Project. I used a resnet-18 model and trained it on the COVID-19 Radiography Dataset. This dataset has nearly 3000 Chest X-Ray scans which are categorized into three classes - Normal, Viral Pneumonia, and COVID-19. The objective of this project was to create an image classification model that could accurately predict and classify the Chest X-Ray scans.

Home Page: https://lopez-christian.github.io/2020-09-28-covid-19-pytorch-image-classifier/

Jupyter Notebook 100.00%
covid19 pytorch flatiron-school datascience deep-learning machine-learning classifying-images covid dataset dataloaders torchvision flatiron-school-project kaggle python jupyter-notebook

covid-19-pytorch-image-classifier's Introduction

Building a COVID-19 Resnet18 PyTorch Image Classifier

Detecting COVID-19 using images from COVID-19 Radiography Database from Kaggle

Screen Shot 2020-09-28 at 8 59 47 PM

Screen Shot 2020-09-28 at 9 24 33 PM

The purpose of this project was to create a resnet18 convolutional neural network using PyTorch that would be capable of classifying images from the COVID-19 Radiography Database Dataset from Kaggle.com click here.

Screen Shot 2020-09-28 at 9 26 50 PM

I started the project by first importing all the necessary libraries and modules. We need to make sure we are importing the most up-to-date PyTorch version available. PyTorch is an open source machine learning library based on the Torch library. It is commonly employed for computer vision and natural language processing tasks. PIL will be used to display the images from our training and test sets. We will also be utilizing torchvision to perform the image transformations and augmentations on our training set during the training phase of the project.

Screen Shot 2020-09-28 at 9 12 39 PM

Next, came the training and test set preparation along with creating a custom dataset, if need be. It consists of cycling through the relevant folders and deriving the necessary images to create the training and test sets to be used in the project. The class is created from torch.utils.data.Dataset. Below is the framework of the class that will need to be generated:

Screen Shot 2020-09-28 at 9 37 08 PM

DataLoaders need to be created that will aid in populating the sets from the images in each of the folders. These essentially fetch examples to feed the model during the training process. The DataLoaders iterate over the folders containing the images and tell us how many images are in each. Allowing us to correctly segmentate the relevant images into their respective categories.

This is for training:

Screen Shot 2020-09-28 at 9 42 21 PM

This is for testing:

Screen Shot 2020-09-28 at 9 42 31 PM

For reference, this is a visual representation of the training and test batch sizes we will be utilizing:

Screen Shot 2020-09-28 at 9 58 19 PM

We then proceed to the visualization phase of the project where we create a helper function that forms part of the training loop. This function converts the tensorflow images back to numpy arrays. It also undoes the normalization performed in the previous step using mean and standard deviation (std). The image pixel values are converted back to their orginal values and displayed using subplot.

Screen Shot 2020-09-28 at 10 05 30 PM

Screen Shot 2020-09-28 at 10 05 52 PM

Then comes the model creation juncture of the project. We use the resnet18 model imported from torchvision.models. It comes ready with pre-trained weights, having been trained on the ImageNet Dataset. This image database is comprised of hundreds and thousands of images. This makes it quite a robust model to play with and serves our purpose perfectly. Not without first adjusting one of the parameters found in the fully-connected layer of the resnet18 model architecture. The resnet18 model comes with a pre-defined out_features parameter of 1000 and we only need 3 (normal, viral, covid). We also set the desired optimization and learning rate.

Screen Shot 2020-09-28 at 10 17 53 PM

The most interesting and fun part is the training phase of the project. Wherein, we witness the runnning of our epochs and the training of our model. We see validation loss and accuracy scores for every 20 steps ran. The model is ran until we reach a classification accuracy of >95% as per our specified acceptance threshold.

Screen Shot 2020-09-28 at 10 21 22 PM

Screen Shot 2020-09-28 at 10 21 48 PM

These are our final predictions illicited by our COVID-19 resnet18 PyTorch Image Classifier ...

Screen Shot 2020-09-28 at 10 25 17 PM

It is not 100% accurate, so we must expect some mistakes ...

Screen Shot 2020-09-28 at 10 25 27 PM

Key takeways:

1. This resnet18 image classifier can play an essential role in clinical treatments and teaching tasks. Doctors and medical practitioners can use the predictions illicited by the model to guide their intuition and make more informed decisions.

2. The model can be trained even further by providing it with more pre-labeled medical image datasets. A significant amount of medical expertise is needed to correctly label the images that will be fed to the model, but eventually the model will be very adept when classifying novel data.

3. Over time, the model will be able to correctly classify vast amounts of data with significant accuracy and minimal validation loss. This resnet18 image classifier can then be utilized an a myriad of ways, including but not limited to, the detection of new strains of COVID. This would undoubtably lead to noteworthy discoveries that will lead to advances in the medical field.

covid-19-pytorch-image-classifier's People

Contributors

lopez-christian avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.