Pneumonia Detection From Chest X-Ray Images Using CNN

Pneumonia Detection From X-ray Images Using Convolutional Neural Network

Pneumonia Detection From Chest X-ray Images using CNN  is a web application built on Python, Django, and Resnet-50 model (Keras Implementation). Convolution Neural Network Resnet-50 is 50 layers deep neural network trained on the Imagenet dataset. Pretrained model can classify images into 1000 objects. So, we used transfer learning to custom train on Chest X-ray images, and modify the network to predict two classes “Normal” and “Pneumonia”.

This application demonstrates the ability of deep learning to solve many complex problems. You can easily build web applications, and serve Convolutional Neural Network using Django, a powerful Python web framework.

What is Pneumonia?

Pneumonia is a contagious disease, this means it can spread from one person to another person. It can affect one or both lungs. It may be caused by bacteria viruses or fungi.

Specifically, infants younger than age 2 and people over age 65 are at higher risk. As their immune systems might not be strong enough to fight this disease. Although everyone prone to catch this lung infection.

Deep Learning For Pneumonia Detection From X-Ray Images

Deep learning has found a wider application in solving computer vision tasks. It has made rapid progress over a short span and performed state-of-the-art results on challenging computer vision problems such as image classification, image segmentation, object detection, face recognition, and self-driving cars.

It seems like a daunting task to train a deep learning model but frameworks like TensorFlow and Keras have simplified to train the model.

For this application, we have trained the ResNet-50 model on Chest X-Ray Images using transfer learning. You can download Chest X-Ray Images from Kaggle.

Interested in another Healthcare use-case: Diabetic Retinopathy Detection using DenseNet

Convolutional Neural Network: Keras ResNet-50 Model

ResNet-50, a Convolutional Neural Network also called a residual neural network,  is a 50 layer deep. There are many variants of ResNet architecture such as ResNet-18, ResNet-34, ResNet-50, ResNet-101, ResNet-110, ResNet-152, ResNet-164, ResNet-1202 etc. 

def create_model(input_shape, n_out):
input_tensor = Input(shape=input_shape)
base_model = ResNet50(input_tensor=input_tensor, include_top=False, pooling='average')
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1000, activation='relu')(x)
x = Dense(n_out, activation='softmax')(x)
model = Model(base_model.input, x)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model

Web Application Capabilities

Pneumonia Detection From X-ray Images using ResNet-50 Convolutional Neural Network web application has the following functionalities:

  • New User Registration Page
  • Login and Logout
  • Generic Pages – Home, About and Contact Us
  • Upload Images – User-friendly interface to upload patient information
  • Automatic ResNet-50 inference on the chest X-Ray images
  • Generates user-friendly reports
  • Manage reports – show result, update and delete data

Technology Stack

Pneumonia Detection From X-ray Images using ResNet-50 Convolutional Neural Network web application built on following technology stack:

  • Python
  • Django – a Python Web Framework
  • Convolutional Neural Network – Keras Resnet-50 Model
  • SQLite