Downloads · 30 days
0
Jlichwa/Pneumonia-Detector-Models
Pneumonia-Detector-Models is a image classification model from Jlichwa. Use it when you need a label for an image. It is set up for fastai, customtransform.py. The card lists the license as mit.
This repository contains deep learning models for a two-stage chest X-ray classification pipeline trained on pediatric data.
Downloads · 30 days
0
Access
Public
Updated Jan 23, 2026
Repo size
1.3 GB
Likes
0
Public
Click a slice to open those files.
.pkl412 MB · 66%
From the Hugging Face model README
This repository contains deep learning models for a two-stage chest X-ray classification pipeline trained on pediatric data.
Stage 1: Classifies images as Normal vs Pneumonia
Stage 2: Classifies Pneumonia into Viral vs Bacterial
Both stages use ResNet-50 backbone with transfer learning and custom image preprocessing techniques.
This repository contains:
set2_stage1_bacterial_viral_detector_final - Stage 1 model (Normal-Pneumonia) Python 3.12set2_stage1_bacterial_viral_detector_final_310 - Stage 1 model (Normal-Pneumonia) - Python 3.10 (HuggingFace Spaces compatible)set2_stage2_bacterial_viral_detector_final - Stage 2 model - Python 3.12set2_stage2_bacterial_viral_detector_final_310 - Stage 2 model - Python 3.10 (HuggingFace Spaces compatible)customtransform.py - CLAHE, Colormap image transofrms applied at runtime before send to modelimage_processing.py - 2 stage model usage exampleImportant: This model requires the custom transforms module included in this repository.
Download: customtransform.py from this repo
The transforms include:
Make sure to download and include customtransform.py in your working directory when using these models.
fastai
torch
torchvision
numpy
PIL
from fastai.vision.all import *
import customtransform # Required - download from this repo
# Load Stage 1 model (Normal vs Pneumonia)
learn_stage1 = load_learner('set2_stage2_pneumonia_detector_final_310.pkl')
# Make prediction
img = PILImage.create('chest_xray.jpg')
pred_class, pred_idx, probs = learn_stage1.predict(img)
# If Pneumonia detected, use Stage 2 (Viral vs Bacterial)
if pred_class == 'Pneumonia':
learn_stage2 = load_learner('set2_stage2_bacterial_viral_detector_final_310.pkl')
subtype_class, subtype_idx, subtype_probs = learn_stage2.predict(img)
print(f"Pneumonia subtype: {subtype_class}")
The models are trained and evaluated on the Chest X-Ray Images (Pneumonia) dataset by Paul Mooney from Kaggle.
| Set | Stage | Accuracy | Precision (Pneumonia) | Recall (Pneumonia) | F1-score (Pneumonia) | Confusion Matrix (TN, FP / FN, TP) |
|---|---|---|---|---|---|---|
| Set 1 | Stage 1 | 0.806 | 0.767 | 0.990 | 0.865 | 117, 117 / 4, 386 |
| Set 2 | Stage 1 | 0.848 | 0.804 | 1.000 | 0.891 | 139, 95 / 0, 390 |
We tuned the decision threshold for the Pneumonia class on the validation set to improve precision while maintaining high recall.
| Threshold Setting | Precision (Pneumonia) | Recall (Pneumonia) | F1-score (Pneumonia) |
|---|---|---|---|
| Before (t = 0.50) | 0.625 | 1.000 | 0.769 |
| After calibration (t = 0.80) | 0.760 | 0.956 | 0.847 |
Raising the threshold from 0.50 to 0.80 increases precision and slightly reduces recall, resulting in a higher F1-score and fewer false positives for Pneumonia detection.
| Set | Stage | Accuracy | Macro Precision | Macro Recall | Macro F1-score | Confusion Matrix (TN, FP / FN, TP) |
|---|---|---|---|---|---|---|
| Set 1 | Stage 2 | 0.897 | 0.926 | 0.866 | 0.884 | 241, 1 / 39, 109 |
| Set 2 | Stage 2 | 0.887 | 0.905 | 0.859 | 0.874 | 236, 6 / 38, 110 |
Metrics for Stage 2 are macro-averaged across the Viral and Bacterial classes. Confusion matrices show strong performance in distinguishing between pneumonia subtypes.
If you use these models or this repository, please cite:
@software{lichwa_pneumonia_detector_2025,
author = {Lichwa, Jack},
title = {Pneumonia Detection - Two-Stage Classification Models},
year = {2025},
version = {1.0},
url = {https://huggingface.co/Jlichwa/Pneumonia-Detector-Models}
}
And also cite the dataset:
@dataset{mooney2018chestxraypneumonia,
author = {Mooney, Paul},
title = {Chest X-Ray Images (Pneumonia)},
year = {2018},
note = {Kaggle dataset},
url = {https://www.kaggle.com/datasets/paultimothymooney/chest-xray-pneumonia}
}
MIT License - See LICENSE file for details.
For questions or collaborations, please open an issue on this repository or reach out via the Hugging Face community forum.