Before we get into the code, let’s learn a bit more about pneumonia.
Pneumonia is a type of lung inflammation caused by viral or bacterial infections. These infections may lead to the filling of the air sacks in your lungs with fluids — which can cause coughing, high fevers, chills, and difficulty breathing.
Sadly, millions of children worldwide are affected by this.
That’s why it should be taken very seriously.
So if your doctor has any reason to believe that you have pneumonia, a chest X-ray will be performed to figure out two factors: The location of the infection and how far it has spread.
Traditionally, when the X-ray is completed, a doctor will analyze the images to find those factors. However, they may not always be correct.
Because pneumonia is one of the most misdiagnosed medical conditions.
So if a patient has pneumonia but is misdiagnosed as without it, their condition can drastically worsen —sometimes leading to death.
But there is one way that we can change this.
Artificial Intelligence!
Now, what is AI. You hear me talking about it, but do you really know it?
Well, in simple terms,
“Artificial Intelligence refers to a machine’s ability to learn and act intelligently — meaning that they can make decisions, carry out tasks and even predict future outcomes based on what they learn from data.”
– Credit: Tech Trends in Practice by Bernard Marr
In our case here, AI can be used to analyze X-ray images to diagnose Pneumonia using datasets of Pneumonia vs Normal chest X-rays.
This will be explained more in-depth with the code in the sections below.
To solve this, we can use a Deep Learning model — Convolutional Neural Network (CNN).
Deep learning is essentially a subset of Machine Learning and AI.
Convolutional Neural Networks (CNNs)
A CNN is a type of deep learning model which can be used to analyze images by extracting features from an input image by applying a filter. This results in an activation. When this process is repeated, we get a map of activations (also known as a feature map). A feature map indicates the locations and strength of a detected feature in an input, such as an image.
When detecting lungs with pneumonia and lungs without pneumonia, we can use this principle to detect the opacity level in the X-ray image — used to help diagnose pneumonia (as seen below).
Alright! The part everyone was waiting for, the process.
Before we get into coding the AI system, we need to download a dataset that allows us to train our model — allowing it to make its predictions.