--- license: cc-by-nc-4.0 datasets: - chest-xray-pneumonia library_name: PyTorch tags: - pneumonia-detection - cnn - medical-imaging - binary-classification - chest-xray - healthcare - pytorch model-index: - name: ImprovedPneumoniaCNN results: - task: type: image-classification name: Pneumonia Detection metrics: - name: Accuracy type: accuracy value: 0.9676 - name: F1 Score type: f1 value: 0.9685 - name: AUC type: auc value: 0.9959 - name: Loss type: loss value: 0.0778 --- # 🧠 ImprovedPneumoniaCNN: Pneumonia Detection from Chest X-rays This repository hosts `ImprovedPneumoniaCNN`, a custom Convolutional Neural Network model designed to detect **Pneumonia** from chest X-ray images. It incorporates enhancements like dropout, batch normalization, SiLU activation, and Convolutional Block Attention Module (CBAM) for improved robustness and generalization. --- ## 📊 Evaluation Results | Metric | Score | |----------|---------| | Accuracy | 96.76% | | F1 Score | 0.9685 | | AUC | 0.9959 | | Loss | 0.0778 | --- ### Confusion Matrix [[1680 42] [ 74 1782]] --- ### Classification Report | Class | Precision | Recall | F1-Score | Support | |-----------|-----------|--------|----------|---------| | Normal | 0.96 | 0.98 | 0.97 | 1722 | | Pneumonia | 0.98 | 0.96 | 0.97 | 1856 | --- ## 🏗️ Architecture Highlights - Custom CNN with residual blocks - Uses **CBAM** attention for spatial and channel refinement - **SiLU** activation for better non-linearity - **Dropout** and **BatchNorm** for regularization - Final **Global Average Pooling** + FC layer --- ## 🚀 How to Use ### 🔧 Install Dependencies ```bash pip install torch torchvision albumentations scikit-learn matplotlib seaborn import torch from torchvision import transforms from PIL import Image from model import ImprovedPneumoniaCNN # make sure model is defined/imported # Load model model = ImprovedPneumoniaCNN() model.load_state_dict(torch.load("improved_pneumonia_cnn.pth", map_location=torch.device('cpu'))) model.eval() # Preprocess image transform = transforms.Compose([ transforms.Grayscale(), transforms.Resize((224, 224)), transforms.ToTensor(), ]) img = Image.open("path_to_chest_xray.jpg") img_tensor = transform(img).unsqueeze(0) # Predict with torch.no_grad(): output = model(img_tensor) prediction = torch.sigmoid(output).item() print("Pneumonia" if prediction > 0.5 else "Normal") ``` --- ## Contributors - [Thiyaga158](https://huggingface.co/Thiyaga158) --- ## License This model is licensed under [CC BY-NC 3.0](https://creativecommons.org/licenses/by-nc/3.0/). For research and educational use only. ---