Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
tags:
|
| 4 |
+
- deep-learning
|
| 5 |
+
- computer-vision
|
| 6 |
+
- medical-imaging
|
| 7 |
+
- chest-xray
|
| 8 |
+
- pneumonia
|
| 9 |
+
- keras
|
| 10 |
+
- tensorflow
|
| 11 |
+
license: cc-by-4.0
|
| 12 |
+
datasets:
|
| 13 |
+
- chest-xray-pneumonia
|
| 14 |
+
widget:
|
| 15 |
+
- text: Upload a chest X-ray image (.jpg or .png)
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# 🩻 Pneumonia Detection Model (CNN)
|
| 19 |
+
|
| 20 |
+
## 🧠 Overview
|
| 21 |
+
This model is a **Convolutional Neural Network (CNN)** trained to classify **chest X-ray images** as either **Normal** or **Pneumonia**.
|
| 22 |
+
It demonstrates the application of **deep learning** to **medical imaging classification** and serves as an **educational and research tool** — **not** for clinical use.
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## ⚙️ Model Details
|
| 27 |
+
|
| 28 |
+
- **Architecture:** Custom CNN (3 convolutional + 2 dense layers)
|
| 29 |
+
- **Framework:** TensorFlow / Keras
|
| 30 |
+
- **Input size:** 150×150 RGB images
|
| 31 |
+
- **Output:** Binary classification — `0 = Normal`, `1 = Pneumonia`
|
| 32 |
+
- **Dataset:** *Chest X-Ray Images (Pneumonia)* — [Kermany et al., *Cell* (2018)](http://www.cell.com/cell/fulltext/S0092-8674(18)30154-5)
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## 📚 Dataset Information
|
| 37 |
+
|
| 38 |
+
**Source:**
|
| 39 |
+
Kermany, D.S., Goldbaum, M., Cai, W. *et al.*
|
| 40 |
+
*Identifying Medical Diagnoses and Treatable Diseases by Image-Based Deep Learning*,
|
| 41 |
+
*Cell* (2018), 172(5), 1122–1131.e9
|
| 42 |
+
[DOI: 10.1016/j.cell.2018.02.010](https://doi.org/10.1016/j.cell.2018.02.010)
|
| 43 |
+
|
| 44 |
+
**License:** [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/)
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## 🩺 Intended Use
|
| 49 |
+
|
| 50 |
+
This model is designed for:
|
| 51 |
+
- Machine learning and data science education
|
| 52 |
+
- Research in medical image analysis
|
| 53 |
+
- Prototyping of AI healthcare applications
|
| 54 |
+
|
| 55 |
+
⚠️ **Disclaimer:**
|
| 56 |
+
This model is **not a medical device** and **should not be used for clinical or diagnostic purposes**.
|
| 57 |
+
It is provided **solely for educational and research use**.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## 🧩 How It Works
|
| 62 |
+
|
| 63 |
+
1. The user uploads a **chest X-ray image** (`.jpg` or `.png`).
|
| 64 |
+
2. The image is resized to **150×150** pixels and normalized to `[0, 1]`.
|
| 65 |
+
3. The CNN processes the image and outputs a probability:
|
| 66 |
+
- `0 → Normal`
|
| 67 |
+
- `1 → Pneumonia`
|
| 68 |
+
4. The final classification is the class with the highest confidence score.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## 📊 Evaluation Report
|
| 73 |
+
|
| 74 |
+
### 🧾 Classification Metrics
|
| 75 |
+
| Metric | Normal | Pneumonia |
|
| 76 |
+
|:--------|:--------:|:-----------:|
|
| 77 |
+
| **Precision** | 0.962 | 0.829 |
|
| 78 |
+
| **Recall** | 0.659 | 0.985 |
|
| 79 |
+
| **F1-score** | 0.783 | 0.900 |
|
| 80 |
+
| **Support** | 232 | 389 |
|
| 81 |
+
|
| 82 |
+
**Overall accuracy:** 0.863
|
| 83 |
+
**Macro F1-score:** 0.841
|
| 84 |
+
**Weighted F1-score:** 0.856
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
### 📉 ROC Curve
|
| 89 |
+

|
| 90 |
+
|
| 91 |
+
**AUC = 0.959**
|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
### 📊 Confusion Matrix
|
| 96 |
+

|
| 97 |
+
|
| 98 |
+
| True Label | Predicted Normal | Predicted Pneumonia |
|
| 99 |
+
|-------------|------------------|---------------------|
|
| 100 |
+
| **Normal** | 153 | 79 |
|
| 101 |
+
| **Pneumonia** | 6 | 383 |
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## 💡 Example Usage
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
import tensorflow as tf
|
| 109 |
+
import numpy as np
|
| 110 |
+
from tensorflow.keras.preprocessing import image
|
| 111 |
+
|
| 112 |
+
# Load model
|
| 113 |
+
model = tf.keras.models.load_model("cnn_pneumonia.keras")
|
| 114 |
+
|
| 115 |
+
# Load and preprocess image
|
| 116 |
+
img_path = "test_image.jpg"
|
| 117 |
+
img = image.load_img(img_path, target_size=(150, 150))
|
| 118 |
+
img_array = image.img_to_array(img) / 255.0
|
| 119 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 120 |
+
|
| 121 |
+
# Predict
|
| 122 |
+
prediction = model.predict(img_array)[0][0]
|
| 123 |
+
label = "Pneumonia" if prediction > 0.5 else "Normal"
|
| 124 |
+
confidence = prediction if prediction > 0.5 else 1 - prediction
|
| 125 |
+
|
| 126 |
+
print(f"Prediction: {label} ({confidence:.2f} confidence)")
|
| 127 |
+
```
|