Downloads · 30 days
9
7% of all-time downloads
dlopez350/pneumonia_detector
pneumonia_detector is a machine learning model from dlopez350. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras. The card lists the license as cc-by-4.0.
This model is a Convolutional Neural Network (CNN) trained to classify chest X-ray images as either Normal or Pneumonia. It demonstrates the application of deep learning to medical imaging classification and serves as…
Downloads · 30 days
9
7% of all-time downloads
All-time downloads
135
Public
Repo size
58 MB
Likes
1
Public
Click a slice to open those files.
.keras58 MB · 100%
From the Hugging Face model README
This model is a Convolutional Neural Network (CNN) trained to classify chest X-ray images as either Normal or Pneumonia.
It demonstrates the application of deep learning to medical imaging classification and serves as an educational and research tool — not for clinical use.
0 = Normal, 1 = PneumoniaSource:
Kermany, D.S., Goldbaum, M., Cai, W. et al.
Identifying Medical Diagnoses and Treatable Diseases by Image-Based Deep Learning,
Cell (2018), 172(5), 1122–1131.e9
DOI: 10.1016/j.cell.2018.02.010
License: Creative Commons Attribution 4.0 International (CC BY 4.0)
This model is designed for:
⚠️ Disclaimer:
This model is not a medical device and should not be used for clinical or diagnostic purposes.
It is provided solely for educational and research use.
.jpg or .png).[0, 1].0 → Normal1 → Pneumonia| Metric | Normal | Pneumonia |
|---|---|---|
| Precision | 0.962 | 0.829 |
| Recall | 0.659 | 0.985 |
| F1-score | 0.783 | 0.900 |
| Support | 232 | 389 |
Overall accuracy: 0.863
Macro F1-score: 0.841
Weighted F1-score: 0.856

AUC = 0.959

| True Label | Predicted Normal | Predicted Pneumonia |
|---|---|---|
| Normal | 153 | 79 |
| Pneumonia | 6 | 383 |
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
# Load model
model = tf.keras.models.load_model("cnn_pneumonia.keras")
# Load and preprocess image
img_path = "test_image.jpg"
img = image.load_img(img_path, target_size=(150, 150))
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
# Predict
prediction = model.predict(img_array)[0][0]
label = "Pneumonia" if prediction > 0.5 else "Normal"
confidence = prediction if prediction > 0.5 else 1 - prediction
print(f"Prediction: {label} ({confidence:.2f} confidence)")