← All projects

Deep learning ยท Computer vision

Pneumonia Detection from Chest X-Rays

A convolutional neural network in PyTorch that classifies chest X-rays as normal or pneumonia, benchmarked against a logistic-regression baseline, with an honest look at where it goes wrong.

Role
Solo
Data
Kaggle chest X-ray pneumonia dataset
Type
Deep learning
Stack
PyTorch, Python
The short version~20 sec read
Problem

Classify chest X-rays as normal or pneumonia, and find out whether a CNN actually beats a much simpler model.

What I did

Built a three-block CNN and compared it with logistic regression on raw pixels, then analysed false positives and overfitting.

Result

0.98 recall: it catches almost every pneumonia case, but over-predicts pneumonia, so it isn't reliable enough for unaided clinical use.

01The model

  • Three convolutional blocks (Conv2d → ReLU → MaxPool), then two fully connected layers over two classes.
  • Inputs resized to 224×224, with random horizontal flips and small rotations for light augmentation.
  • Cross-entropy loss, Adam (lr 0.001), batch size 32, 5 epochs.
  • Accuracy, precision, recall, F1 and a confusion matrix computed on the test split.

02The baseline

Logistic regression treats every pixel independently, so it can't learn shapes or textures. It's there to show how much the CNN gains from learning visual features directly, and the CNN beats it substantially.

03Results & the trade-off

0.98recall on the test set
2classes: normal, pneumonia
224pxinput resolution

The CNN's strength is recall. It misses very few pneumonia cases. The cost is a high false-positive rate: the model leans towards predicting pneumonia, which I put down to class imbalance in the dataset and the overfitting visible in the training vs validation curve.

In a clinical-support setting this profile is deliberate, because missing a pneumonia case costs more than a false alarm. It still isn't reliable enough for unaided clinical use.

04Limitations & next steps

  • False positives are the main target for improvement.
  • Overfitting: a small dataset and light augmentation leave a widening train/validation gap. Stronger augmentation or more data would help.
  • The dataset's validation split has only a handful of images, so validation accuracy is noisy. The test split is the meaningful evaluation.
  • Architecture: ResNet or DenseNet are the natural next step beyond this simplified CNN.
Next project Sensor Streaming Backend