Deep Learning for Automatic Pneumonia Detection
By: Nabil Madali
Tags: Kaggle, Machine Learning, Medical Diagnosis, Computer Vision, Pneumonia

Pneumonia accounts for about 16% of the total deaths of children under 5 in the world, and is the world’s leading cause of death among children. In the United States alone, about 1 million adults receive treatment in hospitals for pneumonia each year, and 50,000 die from the disease.

The test for pneumonia is usually performed by a well-trained expert by examining a chest X-ray (CXR). It usually manifests as an area or area with increased opacity on CXR. Through clinical history, vital signs and laboratory due to other conditions in the lung, such as fluid overload, bleeding, fluid loss, lung cancer, post-radiotherapy or surgical changes, The diagnosis of CXR pneumonia is very complicated. If possible, comparing the patient’s CXR at different time points and its correlation with clinical symptoms and medical history can help diagnosis.

In order to improve the efficiency and accuracy of diagnostic services, computer-aided diagnosis systems for pneumonia detection have been widely used in the past decade. In many medical image analysis tasks, including detection, classification, and segmentation, the performance of using deep learning methods is better than traditional machine learning methods.

A dataset of tagged chest X-ray images and patient metadata is publicly provided by the Clinical Center of the National Institutes of Health [34]. The database contains orthographic X-ray images from 26,684 unique patients. Each image is marked with one of three different categories in the relevant radiology report:

Normal

No lung opacity/abnormal

Lung opacity.

Normally, the lungs are full of air. When someone has pneumonia, the air in the lungs is replaced by other substances. That is, pulmonary opacity refers to the area that preferentially weakens the X-ray beam, so it is more opaque on the CXR than it should be, which indicates that the lung tissue in this area may be unhealthy.

Examples of the chest X-ray images for (a) ”Normal”, (b) ”No Lung Opacity / Not Normal”, and © ”Lung Opacity” cases. The lung opacities regions are shown on © with red bounding boxes.Source[1]

The Normal category contains data from healthy patients without any pathology.

Images in the “Lung Opaque” category show white fuzzy clouds in the lungs, accompanied by pneumonia, and the turbid areas of the lungs are marked with a bounding box. If more than one area of ​​pneumonia is detected, there can be multiple boxes for any given patient . There are many types of lung opacity, some are related to pneumonia, and some are not related to pneumonia.

The No Lung Opacity/Abnormal category describes data for patients who are visible in the CXR lung opaque area but have not been diagnosed with pneumonia .

The average accuracy (mAP) under different IoU thresholds is used to evaluate the model.

The threshold ranges from 0.4 to 0.75, and the step size is 0.05.

Usually, most of the solutions in machine learning competitions are based on the integration of large and diverse models, data aug-mentation and pseudo labelling, but these methods are not always feasible in real applications.

When testing, we usually want to minimize memory usage and reasoning time.

[1] proposes a solution based on a single model that integrates multiple checkpoints. The model uses SE-ResNext101 pre-trained on ImageNet as the backbone network, and the overall network framework uses RetinaNet SSD.

The overall framework of RetinaNet uses ResNet as the backbone to extract image features, and then extracts 5 feature layers from it to build a feature pyramid network (FPN), and finally connects two independent full convolutions ,the network obtains the category information and position frame information of the object respectively.

The one-stage RetinaNet network architecture uses a Feature Pyramid Network (FPN) backbone on top of a feedforward ResNet architecture (a) to generate a rich, multi-scale convolutional feature pyramid (b). To this backbone RetinaNet attaches two subnetworks, one for classifying anchor boxes © and one for regressing from anchor boxes to ground-truth object boxes (d). The network design is intentionally simple, which enables this work to focus on a novel focal loss function that eliminates the accuracy gap between our one-stage detector and state-of-the-art two-stage detectors like Faster R-CNN with FPN while running at faster speeds.Source [3]

RetinaNet is adopted and the following improvements have been made:

The image with an empty target box is added to the model, and helps to calculate and optimize the loss function .

The additional output of the small anchor has been added to the CNN network in order to process smaller target boxes.

Use one of the following categories (“No lung opacity/abnormal”, “Normal”, “Lung opacity”) to classify the additional output of the global image to the model. Therefore, the total loss is formed by combining the global classification output with the regression loss and the single box classification loss.

Added dropout to the global classification output to reduce overfitting. In addition to additional regularization, it also helps to achieve the best classification and regression results in the same epoch.

In order to achieve reasonable rapid experimentation and standardization, an architecture that achieves a good compromise between accuracy and complexity,a number of different encoder architectures has been tested

Evolution of the validation loss during training for the RetinaNet model with various encoders.Source[1]

The figure shows the verification loss during training of various encoders used in RetinaNet SSD. The SE-ResNext architecture has achieved the best performance of this data set, and has achieved a good compromise between accuracy and complexity.

The original image is scaled to a resolution of 512×512 pixels. Since the original challenge data set is not very large, the following image enhancements are used to reduce overfitting:

Slight rotation (up to 6 degrees)

Shift, zoom, cut

Horizontal flip

For some images, blurring, adding noise, random changes in gamma value; limited increase in brightness/gamma enhancement, etc.

The results of the detection model may vary significantly between epochs and depend largely on the threshold. Before applying the NMS algorithm and optimizing the threshold, the outputs of the 4-fold cross-validation of the same model are combined.

The diagram of the same model ensemble technique.Source[1]

The algorithm automatically locates lung opacities on chest radiographs and demonstrated one of the best performance in the challenge.

The final leader board results in Pneumonia detection challenge showing mAP metric calculated on the private test set.Source[1]

The method described in this paper took second place in the challenge. The model was based on RetineNet SSD with Se-ResNext101 encoders pre-trained on ImageNet dataset, heavy augmentations with custom rotation ,multi-task learning with global classification output and postprocessing .

References