--- license: mit pipeline_tag: image-classification base_model: google/vit-base-patch16-224 tags: - medical-ai - image-classification - pneumonia - chest-xray - gradcam - vit --- # 🫁 Pneumonia Detector ![Python](https://img.shields.io/badge/Python-3.10-blue) ![ViT](https://img.shields.io/badge/ViT-Base%20Patch16%20224-green) ![PyTorch](https://img.shields.io/badge/PyTorch-2.0-red) ![HuggingFace](https://img.shields.io/badge/HuggingFace-Spaces-yellow) ## 🎯 Live Demo 👉 [Try it on Hugging Face Spaces](https://huggingface.co/spaces/mou11/pneumonia-detector) ## 🔍 Overview A medical image classification system that detects pneumonia from chest X-ray images using Vision Transformer (ViT) with Grad-CAM explainability. The model highlights which regions of the X-ray influenced the prediction, making it transparent and trustworthy for medical screening. ## 📊 Results | Metric | Score | |--------|-------| | Overall Accuracy | 87% | | AUC-ROC | 0.9805 | | PNEUMONIA Recall | 1.00 | | NORMAL Precision | 0.99 | ## 📈 Classification Report | Class | Precision | Recall | F1-Score | |-------|-----------|--------|----------| | NORMAL | 0.99 | 0.66 | 0.79 | | PNEUMONIA | 0.83 | 1.00 | 0.91 | ## ✨ Features - ✅ Chest X-ray classification: NORMAL vs PNEUMONIA - ✅ Vision Transformer (ViT) fine-tuned on medical images - ✅ Grad-CAM heatmap visualization for explainability - ✅ Handles class imbalance with weighted loss - ✅ Gradio demo for interactive predictions ## 🏗️ Architecture Chest X-Ray Image → Preprocessing (224x224) → ViT Base Patch16 → Fine-tuned Classifier Head → Prediction + Grad-CAM Heatmap ## 🛠️ Tech Stack | Component | Tool | |-----------|------| | Model | Google ViT Base Patch16 224 | | Framework | PyTorch | | Explainability | Grad-CAM | | Dataset | Chest X-Ray Images (Pneumonia) — Kaggle | | UI | Gradio | | Training | Google Colab T4 GPU | ## 📁 Dataset - **Source:** [Chest X-Ray Images (Pneumonia)](https://www.kaggle.com/datasets/paultimothymooney/chest-xray-pneumonia) - **Total Images:** 5,863 - **Classes:** NORMAL (1,341) vs PNEUMONIA (3,875) - **Split:** Train / Val / Test ## 🚀 How to Use ```python