A deep learning project implementing a Convolutional Neural Network (CNN) for automated classification of white blood cells from microscopic images, achieving 95% accuracy across five cell types.
Author: Muhammad Husnain Ali
- Python - Primary programming language
- TensorFlow - Deep learning framework
- Keras - Neural network API
- Google Colab - Development environment
- NumPy - Numerical computing
- Pandas - Data manipulation
- PIL (Pillow) - Image processing
- Matplotlib - Data visualization
- Seaborn - Statistical visualization
- Scikit-learn - Model evaluation
- KaggleHub - Dataset management
-
Advanced Image Processing
- Automatic image resizing (128x128)
- Pixel normalization
- Data augmentation with rotations and flips
- Balanced class distribution
-
Robust CNN Architecture
- 4-stage convolutional network
- Batch normalization
- Dropout regularization
- MaxPooling for feature selection
-
Performance Optimization
- Early stopping
- Learning rate scheduling
- Model checkpointing
- GPU acceleration
-
Comprehensive Evaluation
- Confusion matrix analysis
- ROC curve generation
- Per-class accuracy metrics
- Real-time prediction visualization
Input (128x128x3)
│
├── Conv Block 1 (64 filters) → BatchNorm → MaxPool → Dropout(0.25)
│
├── Conv Block 2 (128 filters) → BatchNorm → MaxPool → Dropout(0.25)
│
├── Conv Block 3 (256 filters) → BatchNorm → MaxPool → Dropout(0.25)
│
├── Conv Block 4 (512 filters) → BatchNorm → MaxPool → Dropout(0.25)
│
├── Dense(1024) → Dropout(0.5)
│
├── Dense(512) → Dropout(0.5)
│
└── Output(5) → Softmax
- Source: White Blood Cells Dataset
- Classes: 5 WBC types
- Neutrophils (6,231 training images)
- Lymphocytes (2,427 training images)
- Monocytes (561 training images)
- Eosinophils (744 training images)
- Basophils (212 training images)
- Volume: 14,514 images
- Training: 10,175 total
- Training split: 8,140 (80%)
- Validation split: 2,035 (20%)
- Test: 4,339 (Test-A)
- Training: 10,175 total
| Metric | Score |
|---|---|
| Training Accuracy | ~94% |
| Validation Accuracy | ~95% |
| Test Accuracy | ~95% |
| Inference Time | <100ms |
| Model Size | ~50MB |
!pip install kagglehub tensorflow numpy pandas matplotlib seaborn pillow scikit-learn tqdmimport kagglehub
# Download latest version
path = kagglehub.dataset_download("masoudnickparvar/white-blood-cells-dataset")
print("Path to dataset files:", path)Simply execute all cells in code.ipynb sequentially. The notebook will:
- Load and preprocess the dataset
- Display data distribution and sample images
- Build and train the CNN model
- Evaluate performance with metrics and visualizations
- Save the trained model as
wbc_classification_model.keras
tensorflow>=2.8.0
numpy>=1.19.5
pandas>=1.3.0
matplotlib>=3.4.3
seaborn>=0.11.0
pillow>=8.3.0
scikit-learn>=1.0.2
tqdm>=4.62.0
kagglehub>=0.1.0
- Use GPU runtime in Colab for faster training (Runtime → Change runtime type → GPU)
- The notebook includes data augmentation by default
- Training typically takes 10 epochs with early stopping
- Monitor validation metrics to avoid overfitting
from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np
# Load the trained model
model = load_model('wbc_classification_model.keras')
# Load and preprocess image
img = Image.open('path/to/image.jpg').convert('RGB')
img = img.resize((128, 128))
img_array = np.array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
# Predict
prediction = model.predict(img_array)
classes = ["Neutrophil", "Lymphocyte", "Monocyte", "Eosinophil", "Basophil"]
predicted_class = classes[np.argmax(prediction)]
confidence = np.max(prediction)
print(f"Predicted: {predicted_class} with {confidence:.2%} confidence")- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
For questions and support:
- Open an Issue
- Contact: m.husnainali.work@gmail.com
- Kaggle for the comprehensive dataset
- TensorFlow team for the framework
- Google Colab for free GPU resources
- All contributors to this project
Made with ❤️ by Muhammad Husnain Ali