Chest X-Ray Images (Pneumonia)



Machine Learning and Deep Learning have a huge scope in healthcare but applying them in healthcare isn’t that simple.
Pneumonia is an inflammatory condition of the lung affecting primarily the small air sacs known as alveoli. Symptoms typically include some combination of productive or dry cough, chest pain, fever and difficulty breathing. The severity of the condition is variable.

It can be either: 1) Bacterial pneumonia 2) Viral Pneumonia 3) Mycoplasma pneumonia and 4) Fungal pneumonia. This dataset consists pneumonia samples belonging to the first two classes. The dataset consists of only very few samples and that too unbalanced. The aim of this project is to develop a robust deep learning model from scratch on this limited amount of data to predict whether an X-ray scan shows presence of pneumonia. This is especially useful during these current times as COVID-19 is known to cause pneumonia.


Figure 1: Overview of the Dataset
The dataset consists of 5,863 X-Ray images and 2 categories (Pneumonia/Normal). Chest X-ray images (anterior-posterior) were selected from retrospective cohorts of pediatric patients of one to five years old from Guangzhou Women and Children’s Medical Center, Guangzhou. All chest X-ray imaging was performed as part of patients’ routine clinical care. For the analysis of chest x-ray images, all chest radiographs were initially screened for quality control by removing all low quality or unreadable scans. The diagnoses for the images were then graded by two expert physicians before being cleared for training the AI system. In order to account for any grading errors, the evaluation set was also checked by a third expert.
Figure 2: Building Convolutional Neural Network (CNN) – Residual Learning
CNN is the standard in performing image classification task. We used ResNet which is a type of CNN with residual learning feature that allows the learning weights propagate better to the deeper layers of the neural network.

Figure 3: Model Evaluation
Confusion matrix is calculated by applying the completed CNN model to an independent test set comprised on X-ray images unseen during the training process. Precision and recall are the two metrics used to evaluation the model. The precision is 0.88 and the recall is 0.98. The precision tells how many of positive predictions were actually correct. In this example, the model classified that 432 people have Pneumonia and 382 of them indeed have Pneumonia. In medical field, a high precision is very important because we don’t want to give a false diagnosis to a healthy person. On the other hand, the recall tells how many of your actual positive Pneumonia cases were predicted correctly. In this case, 382 Pneumonia cases were predicted correctly among 390 total Pneumonia cases.

What does it do?
The model determines whether or not a patient has pneumonia based on their X-Ray pictures. Clinicians at the radiology department could use the model to assist them in pneumonia diagnosis.

How do I evaluate the project’s success?
I would monitor the results and receive feedbacks from clinicians and ask if those who were correctly diagnosed with pneumonia were aided with the assist of my model.

What did I learn from this project
I learned how common it is for people to get contract pneumonia as over a million people are diagnosed each year. However, such a disease is hard to diagnose as the symptoms of coughing, fever, and chest discomfort is very synonymous with that of the flu or the common cold. Therefore, it was imperative to find other easier solutions to accurately diagnose diseases like pneumonia, like so using X-Rays. While training CNN model, I noticed that my model is overfitting the training data because the test error was a lot lower than the training error. To correct this overfitting, I used the drop out technique to randomly set some activations to 0. I also learned the concept of backpropagation, used to adjust the weight to minimize the loss, and gradient descent, used to find the minimum loss, to understand how neural network algorithms work.

What’s next for this project
This pneumonia diagnostic tool is developed using a dataset with limited cohort from Guangzhou, China. For expanded usage of this tool, we need to build a diagnostic model that covers various race and gender. Once this pneumonia diagnostic tool gains credible reputation, the medical staffs can use this tool to not only diagnose pneumonia, but also assist doctors in confirming such diagnostics retrospectively for quality control purpose.