ARI+THE+SCIENTIST
Computer Vision08 / 09

Image Diagnosis

Lung Diseases Diagnosis Using Deep Learning

Live DemoCode ↗

About this project

A web application that uses computer vision analysis to diagnose and distinguish between Pneumonia and COVID-19 using the VGG19 deep learning algorithm. The purpose is to build a classifier that can correctly distinguish between Pneumonia and Covid-19, motivated by the 100,000 deaths per year due to misdiagnosis of pneumonia and the fact that pneumonia is the leading cause of fatality in children under 5.

Key features

  • 01The network used is VGG19 due to its strong accuracy on image classification problems.
  • 02Pre-trained weights are loaded with include_top=False so the final 1000-class layer is dropped.
  • 03New top layers are added for binary classification (Pneumonia vs Covid-19).
  • 04ImageDataGenerator augments training (batch size 32, image size 64x64).

Methodology & results

Purpose

The goal is a classifier that can correctly distinguish between pneumonia and COVID-19 on a chest X-ray. Why lung diseases in particular:

  • Roughly 100,000 deaths per yearare attributable to misdiagnosed pneumonia. Wrongful diagnosis is life-threatening because it delays treatment — especially when the underlying condition is a more aggressive respiratory infection like COVID-19.
  • Pneumonia accounts for roughly 1 in 6 childhood deaths globally, making it the leading cause of fatality in children under five.
  • The US pneumonia mortality rate sits near 10 per 100,000 — typical of developed economies. In much of sub-Saharan Africa the rate is closer to 100 per 100,000, an order of magnitude higher, reflecting how much room a cheap screening tool has to make a difference.
Figure 1 — Sample classifier output on a held-out chest X-ray.
Figure 1 — Sample classifier output on a held-out chest X-ray.

Model

The backbone is VGG19— well-established on image classification and cheap to fine-tune. ImageNet weights are loaded with include_top=False, dropping the final 1,000-class head that would otherwise be useless for a two-class problem. The input layer is also swapped to accept custom image dimensions. On top of the frozen convolutional stack sit a small dense head and a binary softmax.

Training data flows through ImageDataGeneratorwith a batch size of 32 and images resized to 64×64. Three separate binary classifiers are trained: COVID-19 vs. Normal, Pneumonia vs. Normal, and a multi-class Pneumonia vs. COVID-19 head.

COVID-19 vs. Normal

Accuracy sits at 99%; recall on the positive class is also 99%. Recall is the metric that matters most here: in a screening context, a false negative — missing a real COVID case — is far more costly than a false positive that prompts a second look.

Figure 2a — COVID-19 model training/validation loss.
Figure 2a — COVID-19 model training/validation loss.
Figure 2b — COVID-19 confusion matrix. Off-diagonal errors are near-zero.
Figure 2b — COVID-19 confusion matrix. Off-diagonal errors are near-zero.

Pneumonia vs. Normal

Accuracy: 94%. Recall on pneumonia: 95%. AUC: 0.90. Loss on the held-out set: 0.17. The pneumonia task is genuinely harder than the COVID task — pneumonia opacities are more diffuse and the class boundary less sharp — and the numbers reflect that.

Figure 3a — Pneumonia model loss.
Figure 3a — Pneumonia model loss.
Figure 3b — Pneumonia model ROC. AUC ≈ 0.90.
Figure 3b — Pneumonia model ROC. AUC ≈ 0.90.
Figure 3c — Pneumonia confusion matrix.
Figure 3c — Pneumonia confusion matrix.

Pneumonia vs. COVID-19

The multi-class head separates the two diseases directly. Loss drops to 0.02, AUC climbs to 0.93, and recall on the COVID class reaches 100%. The specialised binary COVID and pneumonia models still contribute value — they can serve as sanity checks on the multi-class output — but the multi-class model is the one you would deploy.

Figure 4a — Pneumonia-vs-COVID model loss.
Figure 4a — Pneumonia-vs-COVID model loss.
Figure 4b — Pneumonia-vs-COVID ROC. AUC ≈ 0.93.
Figure 4b — Pneumonia-vs-COVID ROC. AUC ≈ 0.93.
Figure 4c — Pneumonia-vs-COVID confusion matrix.
Figure 4c — Pneumonia-vs-COVID confusion matrix.

Recommendation

Against a plain baseline the VGG19 fine-tune is roughly 26% better at correctly diagnosing COVID in the binary task and roughly 15% better in the multi-class task. Two improvements are worth wiring in before production:

  • Dropout before the final dense layer. Half the activations from a 512-unit dense layer are dropped during training to keep the model from memorising the small dataset.
  • Multi-class head as the primary output. The binary models are retained only for internal cross-checks.

Future work

  • Other lung diseases. Extend the classifier to tuberculosis, bronchitis, and other pathologies so a single tool can triage a broader differential.
  • Region localisation.Move from image-level classification to lesion detection — where in the lung the infection sits, not just whether it’s present.
  • More data, deeper tuning. Unfreeze more of the VGG19 base and train against a larger, more diverse cohort to shrink the domain-shift gap between hospitals and X-ray hardware.