Skip to content

rantaluca/Pneumonia_classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pneumonia Detection with Deep Learning 🫁

Chest X-ray dataset overview

PyTorch OpenCV scikit-learn Dataset


Overview

This project applies Deep Learning and Computer Vision techniques to detect pneumonia from chest X-ray images.
It uses the Chest X-Ray Pneumonia Dataset from Kaggle (Kermany et al., Cell, 2018) and a DenseNet-121 architecture fine-tuned by transfer learning for binary classification (Normal vs Pneumonia).

This challenge was developed as a personal initiative, building on the knowledge gained during my Deep Learning coursework at ÉTS Montréal.


Dataset & Preprocessing

  • Total: 5 216 training and 624 test images
  • Two classes: NORMAL and PNEUMONIA
  • Basic grayscale normalization and resizing to 224×224
  • Optional histogram equalization and denoising

Dataset Visualization


Model Architecture

  • Backbone: DenseNet-121 pretrained on ImageNet
  • Final layer: Replaced with a 2-class linear layer
  • Loss: Weighted Cross-Entropy (to mitigate imbalance)
  • Optimizer: AdamW (lr = 3e-4, weight_decay = 1e-4)
  • Scheduler: Cosine Annealing
  • Training device: Mac m1 & Ubuntu with RTX 3060 (automatic GPU detection)

Results

Accuracy & F1-score

  • Accuracy: ≈ 93 %
  • Weighted F1-score: 0.93
  • NORMAL: Precision 0.98 | Recall 0.85 | F1 0.91
  • PNEUMONIA: Precision 0.91 | Recall 0.99 | F1 0.95

The model achieves 93 % accuracy and a weighted F1-score of 0.93, showing a strong and balanced performance across both classes. Notably, the model maintains high precision for normal cases (reducing false alarms) while achieving near-perfect recall for pneumonia, ensuring critical cases are rarely missed.

Confusion Matrix


Precision–Recall Curves

Both classes reach Average Precision > 0.95, showing strong separability.
The pneumonia curve stays near the top-right, while the normal class drops slightly in precision at high recall.

Precision Recall Curves


Next Steps

  • Applying stronger data augmentation to the NORMAL class
  • Trying Focal Loss or class reweighting
  • Fine-tuning deeper layers of the DenseNet backbone

Run the Notebook

# Install dependencies
pip install torch torchvision torchaudio opencv-python scikit-learn matplotlib tqdm

# Launch the notebook
jupyter notebook main.ipynb

Author

Robert Antaluca
ÉTS Montréal / Université de Technologie de Compiègne
Website: antaluca.com


Sources

Pneumonia Image Classification Using DenseNet Architecture

Classification of Paediatric Pneumonia Using Modified DenseNet-121 Deep-Learning Model

Dataset


License

MIT License: feel free to modify and build upon this project for research or learning purposes.

About

Transfer Learning to detect pneumonia from chest X-ray images.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors