Deep Learning For Early Diagnosis
Pneumonia is a serious respiratory condition that demands timely and accurate diagnosis. This project introduces an intelligent system that analyzes chest X-ray images to detect signs of pneumonia using deep learning. By fine-tuning a pre-trained VGG16 model, the solution offers fast, reliable classification of X-rays as either Normal or Pneumonia, supporting healthcare professionals in early intervention.
Built with clarity, precision, and real-world utility in mind, this tool demonstrates how AI can enhance diagnostic workflows and reduce the burden on clinical staff.
The model is trained on the Chest X-Ray Images (Pneumonia) dataset, which contains 5,863 labeled images:
- Normal: 1,583 images
- Pneumonia: 4,273 images
All images are resized to 224×224 pixels to match the input requirements of the VGG16 architecture.
This Pneumonia Detection model is built using transfer learning with VGG16 and fine-tuned for binary classification of chest X-ray images. Key architectural and training features include:
-
Architecture:
- Base: VGG16 (pre-trained on ImageNet)
- Top Layers: Flatten + Dense(2) with softmax activation
- Output: Two classes — Normal and Pneumonia
-
Input Configuration:
- Image size: 224×224 pixels
- Color channels: RGB (3-channel input)
-
Training Strategy:
- Frozen convolutional layers to retain learned features
- Augmented training data using shear, zoom, and horizontal flip
- Rescaled pixel values for both training and test sets
- Optimizer: Adam
- Loss Function: Categorical Crossentropy
- Epochs: 5 (configurable for deeper training)
-
Batch Processing:
- Batch size: 32
- Directory-based image loading with categorical labels
-
Model Output:
- Trained model saved as
chest_xray.h5 - Ready for deployment or integration into prediction pipelines
- Trained model saved as
Clone the repository and install dependencies:
git clone https://github.com/Im-Mohammed/PneumoniaDetectionModel.git
cd PneumoniaDetectionModel
pip install -r requirements.txtDownload the dataset from Kaggle and place it in:
./data/chest_xray/
To begin training:
python train.pyYou can adjust key hyperparameters such as batch size, learning rate, and number of epochs:
optimizer = Adam(learning_rate=0.0001)Modify the model.fit() call to experiment with different training durations.
The model achieves a training accuracy of 82%, offering a strong baseline for pneumonia detection. With further tuning and data augmentation, this performance can be improved for deployment-ready use cases.
Experience the model in action:
pnemonia.git.1.mp4
Once trained, you can run predictions on new chest X-ray images:
python predict.py --image path/to/image.jpgThe output will classify the image as either:
- Normal
- Pneumonia
This project welcomes contributions from researchers, developers, and healthcare innovators. If you’d like to improve the model, add new features, or adapt it for broader use cases, feel free to fork the repo and submit a pull request:
git checkout -b feature-branch
git commit -m "Add new feature"
git push origin feature-branchFor questions, feedback, or collaboration opportunities:
📮 Open an Issue
This project is licensed under the MIT License.
You’re free to use, modify, and distribute it with attribution.