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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- medical
|
| 5 |
+
- chest-xray
|
| 6 |
+
- pneumonia-detection
|
| 7 |
+
- healthcare
|
| 8 |
+
- computer-vision
|
| 9 |
+
- keras
|
| 10 |
+
- tensorflow
|
| 11 |
+
datasets:
|
| 12 |
+
- nih-chest-xray
|
| 13 |
+
metrics:
|
| 14 |
+
- accuracy
|
| 15 |
+
- sensitivity
|
| 16 |
+
- specificity
|
| 17 |
+
language:
|
| 18 |
+
- en
|
| 19 |
+
model-index:
|
| 20 |
+
- name: chest-xray-pneumonia-detection
|
| 21 |
+
results:
|
| 22 |
+
- task:
|
| 23 |
+
type: image-classification
|
| 24 |
+
name: Pneumonia Detection
|
| 25 |
+
dataset:
|
| 26 |
+
type: medical-imaging
|
| 27 |
+
name: External Validation Dataset
|
| 28 |
+
metrics:
|
| 29 |
+
- type: accuracy
|
| 30 |
+
value: 0.86
|
| 31 |
+
name: External Validation Accuracy
|
| 32 |
+
- type: sensitivity
|
| 33 |
+
value: 0.964
|
| 34 |
+
name: Sensitivity
|
| 35 |
+
- type: specificity
|
| 36 |
+
value: 0.748
|
| 37 |
+
name: Specificity
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
# Chest X-Ray Pneumonia Detection Model
|
| 41 |
+
|
| 42 |
+
A robust deep learning system for automated pneumonia detection in chest radiographs, featuring comprehensive external validation and clinical-grade performance metrics.
|
| 43 |
+
|
| 44 |
+
## π― Model Overview
|
| 45 |
+
|
| 46 |
+
This model implements a binary classification system designed to identify pneumonia in chest X-ray images. Built on MobileNetV2 architecture with transfer learning, the system has undergone rigorous external validation on 485 independent samples, demonstrating strong clinical applicability and generalization capabilities.
|
| 47 |
+
|
| 48 |
+
### Key Performance Highlights
|
| 49 |
+
|
| 50 |
+
- **External Validation Accuracy**: 86.0% on 485 independent samples
|
| 51 |
+
- **Clinical Sensitivity**: 96.4% - optimal for screening applications
|
| 52 |
+
- **Robust Generalization**: Validated on completely unseen data from independent sources
|
| 53 |
+
- **Production Ready**: Comprehensive evaluation with detailed performance analysis
|
| 54 |
+
|
| 55 |
+
## π Performance Metrics
|
| 56 |
+
|
| 57 |
+
### Validation Results Comparison
|
| 58 |
+
|
| 59 |
+
| Performance Metric | Internal Validation | External Validation | Clinical Assessment |
|
| 60 |
+
|-------------------|-------------------|-------------------|-------------------|
|
| 61 |
+
| **Accuracy** | 94.8% | 86.0% | Excellent generalization (8.8% variance) |
|
| 62 |
+
| **Sensitivity (Recall)** | 89.6% | 96.4% | Outstanding screening capability |
|
| 63 |
+
| **Specificity** | 100.0% | 74.8% | Acceptable false positive management |
|
| 64 |
+
| **Precision (PPV)** | 100.0% | 80.4% | Strong positive predictive value |
|
| 65 |
+
| **F1-Score** | 94.5% | 87.7% | Well-balanced performance profile |
|
| 66 |
+
|
| 67 |
+
### External Validation Dataset
|
| 68 |
+
- **Sample Size**: 485 radiographs (234 normal, 251 pneumonia cases)
|
| 69 |
+
- **Data Source**: Independent pneumonia radiography dataset
|
| 70 |
+
- **Validation Method**: Complete external testing on previously unseen data
|
| 71 |
+
- **Statistical Significance**: Large sample size ensures reliable performance estimates
|
| 72 |
+
|
| 73 |
+
## π¬ Clinical Significance
|
| 74 |
+
|
| 75 |
+
### Screening Applications
|
| 76 |
+
The model's **96.4% sensitivity** makes it particularly suitable for pneumonia screening workflows, where missing positive cases carries high clinical risk. The balanced performance profile supports its use as a clinical decision support tool.
|
| 77 |
+
|
| 78 |
+
### Generalization Capability
|
| 79 |
+
With only an 8.8% accuracy decrease from internal to external validation, the model demonstrates robust learning patterns that generalize well across different data sources and imaging protocols.
|
| 80 |
+
|
| 81 |
+
## π Implementation Guide
|
| 82 |
+
|
| 83 |
+
### Quick Start Example
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
import tensorflow as tf
|
| 87 |
+
from tensorflow.keras.preprocessing import image
|
| 88 |
+
import numpy as np
|
| 89 |
+
|
| 90 |
+
# Load the pre-trained model from Hugging Face Hub
|
| 91 |
+
from huggingface_hub import hf_hub_download
|
| 92 |
+
|
| 93 |
+
# Download model from Hugging Face Hub
|
| 94 |
+
model_path = hf_hub_download(
|
| 95 |
+
repo_id="ayushirathour/chest-xray-pneumonia-detection",
|
| 96 |
+
filename="best_chest_xray_model.h5"
|
| 97 |
+
)
|
| 98 |
+
model = tf.keras.models.load_model(model_path)
|
| 99 |
+
|
| 100 |
+
def predict_pneumonia(img_path):
|
| 101 |
+
"""
|
| 102 |
+
Predict pneumonia from chest X-ray image
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
img_path (str): Path to chest X-ray image
|
| 106 |
+
|
| 107 |
+
Returns:
|
| 108 |
+
dict: Prediction results with confidence scores
|
| 109 |
+
"""
|
| 110 |
+
# Load and preprocess image
|
| 111 |
+
img = image.load_img(img_path, target_size=(224, 224))
|
| 112 |
+
img_array = image.img_to_array(img) / 255.0
|
| 113 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 114 |
+
|
| 115 |
+
# Generate prediction
|
| 116 |
+
prediction = model.predict(img_array)[0][0]
|
| 117 |
+
|
| 118 |
+
# Interpret results
|
| 119 |
+
if prediction > 0.5:
|
| 120 |
+
result = {
|
| 121 |
+
'diagnosis': 'PNEUMONIA',
|
| 122 |
+
'confidence': f"{prediction:.1%}",
|
| 123 |
+
'recommendation': 'Clinical review recommended'
|
| 124 |
+
}
|
| 125 |
+
else:
|
| 126 |
+
result = {
|
| 127 |
+
'diagnosis': 'NORMAL',
|
| 128 |
+
'confidence': f"{1-prediction:.1%}",
|
| 129 |
+
'recommendation': 'No pneumonia indicators detected'
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
return result
|
| 133 |
+
|
| 134 |
+
# Example usage
|
| 135 |
+
results = predict_pneumonia("chest_xray_sample.jpg")
|
| 136 |
+
print(f"Diagnosis: {results['diagnosis']}")
|
| 137 |
+
print(f"Confidence: {results['confidence']}")
|
| 138 |
+
print(f"Recommendation: {results['recommendation']}")
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
### Model Architecture Details
|
| 142 |
+
|
| 143 |
+
- **Base Architecture**: MobileNetV2 with transfer learning optimization
|
| 144 |
+
- **Input Specifications**: 224Γ224 pixel RGB chest X-ray images
|
| 145 |
+
- **Output Format**: Binary classification probabilities (Normal/Pneumonia)
|
| 146 |
+
- **Framework**: TensorFlow 2.x / Keras
|
| 147 |
+
- **Model Size**: Optimized for clinical deployment scenarios
|
| 148 |
+
|
| 149 |
+
## π Performance Visualizations
|
| 150 |
+
|
| 151 |
+
### External Validation Results
|
| 152 |
+
|
| 153 |
+

|
| 154 |
+
*Detailed classification results with percentage breakdown*
|
| 155 |
+
|
| 156 |
+

|
| 157 |
+
*Internal vs External validation performance comparison*
|
| 158 |
+
|
| 159 |
+

|
| 160 |
+
*Clinical balance optimization for screening applications*
|
| 161 |
+
|
| 162 |
+

|
| 163 |
+
*Balanced external validation dataset distribution*
|
| 164 |
+
|
| 165 |
+
## π Clinical Applications
|
| 166 |
+
|
| 167 |
+
### Primary Use Cases
|
| 168 |
+
1. **Pneumonia Screening Programs**: High-sensitivity detection for population screening
|
| 169 |
+
2. **Clinical Decision Support**: Augmenting radiologist workflow with AI insights
|
| 170 |
+
3. **Triage Optimization**: Prioritizing cases requiring urgent clinical attention
|
| 171 |
+
4. **Medical Education**: Demonstrating AI validation methodologies in healthcare
|
| 172 |
+
|
| 173 |
+
### Implementation Considerations
|
| 174 |
+
- **Screening Focus**: Optimized for high sensitivity to minimize missed diagnoses
|
| 175 |
+
- **Clinical Oversight**: Designed to support, not replace, professional medical judgment
|
| 176 |
+
- **Quality Assurance**: Comprehensive validation ensures reliable performance metrics
|
| 177 |
+
|
| 178 |
+
## β οΈ Usage Guidelines & Limitations
|
| 179 |
+
|
| 180 |
+
### Clinical Limitations
|
| 181 |
+
- **Diagnostic Support Only**: Not intended as a standalone diagnostic tool
|
| 182 |
+
- **Professional Supervision Required**: All results require clinical interpretation
|
| 183 |
+
- **False Positive Management**: 25.2% false positive rate necessitates clinical review
|
| 184 |
+
- **Population Considerations**: Performance may vary across different demographic groups
|
| 185 |
+
|
| 186 |
+
### Technical Considerations
|
| 187 |
+
- **Dataset Scope**: Trained on specific chest X-ray imaging protocols
|
| 188 |
+
- **Input Requirements**: Optimal performance requires standard posteroanterior chest radiographs
|
| 189 |
+
- **Quality Dependencies**: Image quality significantly impacts prediction accuracy
|
| 190 |
+
|
| 191 |
+
## π Dataset & Training Information
|
| 192 |
+
|
| 193 |
+
### Training Dataset
|
| 194 |
+
- **Primary Source**: NIH Chest X-ray Dataset (carefully balanced subset)
|
| 195 |
+
- **Preprocessing Pipeline**: Standardized resizing, normalization, and augmentation
|
| 196 |
+
- **Quality Control**: Systematic filtering for optimal training data quality
|
| 197 |
+
|
| 198 |
+
### External Validation Protocol
|
| 199 |
+
- **Independent Dataset**: 485 samples from completely separate data source
|
| 200 |
+
- **Balanced Composition**: 234 normal cases, 251 pneumonia cases
|
| 201 |
+
- **Validation Rigor**: Zero data leakage between training and validation sets
|
| 202 |
+
|
| 203 |
+
## π Repository Contents
|
| 204 |
+
|
| 205 |
+
| File | Description |
|
| 206 |
+
|------|-------------|
|
| 207 |
+
| `best_chest_xray_model.h5` | Production-ready trained Keras model |
|
| 208 |
+
| `comprehensive_external_validation_results.csv` | Detailed performance metrics and analysis |
|
| 209 |
+
| `classification_report.csv` | Complete sklearn classification report |
|
| 210 |
+
| `*.png` | Professional visualization suite (8 comprehensive charts) |
|
| 211 |
+
|
| 212 |
+
## π Citation & Attribution
|
| 213 |
+
|
| 214 |
+
If this model contributes to your research or clinical work, please cite:
|
| 215 |
+
|
| 216 |
+
```bibtex
|
| 217 |
+
@misc{rathour2025chestxray,
|
| 218 |
+
title={Chest X-Ray Pneumonia Detection: Externally Validated Deep Learning System},
|
| 219 |
+
author={Rathour, Ayushi},
|
| 220 |
+
year={2025},
|
| 221 |
+
note={External validation study on 485 independent samples with clinical performance analysis},
|
| 222 |
+
url={https://huggingface.co/ayushirathour/chest-xray-pneumonia-detection}
|
| 223 |
+
}
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
## π©βπ» Author & Contact
|
| 227 |
+
|
| 228 |
+
**Ayushi Rathour** - Medical AI Research & Development
|
| 229 |
+
|
| 230 |
+
- π **GitHub**: [@ayushirathour](https://github.com/ayushirathour)
|
| 231 |
+
- πΌ **LinkedIn**: [Ayushi Rathour](https://linkedin.com/in/ayushi-rathour)
|
| 232 |
+
- π§ **Email**: [email protected]
|
| 233 |
+
|
| 234 |
+
---
|
| 235 |
+
|
| 236 |
+
## π₯ Advancing Medical AI Through Rigorous Validation
|
| 237 |
+
|
| 238 |
+
*This model exemplifies the critical importance of external validation in medical artificial intelligence, achieving clinical-grade performance through systematic methodology, comprehensive evaluation, and transparent reporting of both capabilities and limitations.*
|
| 239 |
+
|
| 240 |
+
---
|
| 241 |
+
|
| 242 |
+
**License**: MIT | **Tags**: medical, chest-xray, pneumonia-detection, healthcare, computer-vision, keras
|