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
Normal | Pneumonia |
---|---|
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
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
License
This model is licensed under CC BY-NC 3.0.
For research and educational use only.
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support
Evaluation results
- Accuracyself-reported0.968
- F1 Scoreself-reported0.969
- AUCself-reported0.996
- Lossself-reported0.078