To accurately diagnose ailments, doctors need every possible tool at their disposal. Now with the growing use of machine learning (ML) in healthcare, we wanted to see how quickly we could create an image classification model that could give doctors an upper hand in diagnosing patients' ailments, specifically pneumonia.
To accomplish this, we built an ML model that can classify images of chest x-rays as either normal or infected. This involved preparing and wrangling the training data, building a .csv file to map that data to the two classifications, and iterating with the model in PerceptiLabs. Let's see how we did.
We grabbed the chest x-ray images from this Kaggle project and pre-processed each of them into a resolution of 224 x 224 pixels:
Since transfer learning is being used, we were able to use a smaller dataset while still getting good model performance.
We pre-processed the images to resize each of them into a resolution of 224x224 pixels and created a .csv file to map the images to their respective classification enumerations. Below is a partial example of how the .csv file looks:
Example of a .csv file to load data into PerceptiLabs where 0 is normal and 1 is infected.
In the Data Wizard we set the first column to be Input of type Image, and the second column to a Target of type Categorical; partitioning allocations were left as PerceptiLabs' defaults (70% training, 20% validation, and 10% testing) with randomization enabled.
Our model was built with just three Components:
|Component 1: ResNet50||include_top=No, input_shape=(224,224)|
|Component 2: Dense||Activation=ReLU, Neurons=128|
|Component 3: Dense||Activation=Softmax, Neurons=10|
Training and Results
With a training time of 2 minutes and 44 seconds, we were able to achieve a training accuracy of 99.54% and a validation accuracy of 93.5%. In the following screenshot from PerceptiLabs, you can see how the training accuracy quickly ramped up during the first epoch, while validation accuracy remained fairly stable:
At the same time, training loss decreased the most during the first epoch, while validation loss grew slightly across epochs:
In the realm of patient diagnosis and care, a model like this could be used to automate the process of examining x-rays, and to notify doctors as to which x-rays require may indicate an ailment.
Such a project could also potentially be used by dentists, physiotherapists, pathologists, researchers, medical schools, veterinarians, and other healthcare providers to speed up the process of examining x-rays. And the model itself could be used as the basis for transfer learning to create models that detect other ailments from x-ray images.
This use case is a simple example of how ML can be used to identify ailments using image recognition. If you want to build a deep learning model similar to this, run PerceptiLabs and grab a copy of our pre-processed dataset from GitHub.