- Project Overview
- Dataset Information
- Model Architecture
- Data Preprocessing
- Training Process
- Results & Performance
- Visualizations
- Installation
- Future Improvements
- References
This project implements a deep learning solution for brain tumor classification using Convolutional Neural Networks (CNN) and transfer learning with NASNetMobile. The model classifies brain MRI images into multiple categories to assist in medical diagnosis and treatment planning.
- β Multi-class brain tumor classification
- β Transfer learning with NASNetMobile architecture
- β Data augmentation for improved generalization
- β Comprehensive model evaluation with multiple metrics
- β Visualization of training progress and predictions
- Develop an accurate automated brain tumor classification system
- Leverage pre-trained NASNetMobile for efficient feature extraction
- Achieve high accuracy and reliability for clinical assistance
- Provide interpretable results through visualization
Dataset: Brain tumors 256x256
Source: Kaggle Dataset
Brain-Tumors-256x256/
βββ Training/
β βββ glioma/
β βββ meningioma/
β βββ notumor/
β βββ pituitary/
βββ Testing/
βββ glioma/
βββ meningioma/
βββ notumor/
βββ pituitary/
| Category | Description | Clinical Significance |
|---|---|---|
| Glioma | Most common primary brain tumor originating from glial cells | Aggressive, requires immediate treatment |
| Meningioma | Tumor arising from meninges (protective membranes) | Usually benign, slow-growing |
| Pituitary | Tumor in the pituitary gland | Affects hormone regulation |
| No Tumor | Normal brain MRI without tumor presence | Normal |
π Dataset Distribution:
ββββββββββββββββββββββββββββββββββββββββββββββ
Training Set:
β’ Glioma: 722 images (~29%)
β’ Meningioma: 351 images (~14%)
β’ No Tumor: 731 images (~29.5%)
β’ Pituitary: 675 images (~27%)
β’ Total: 2479 images
Validation Set:
β’ Glioma: 89 images
β’ Meningioma: 43 images
β’ No Tumor: 91 images
β’ Pituitary: 84 images
β’ Total: 307 images
Testing Set:
β’ Glioma: 90 images
β’ Meningioma: 44 images
β’ No Tumor: 91 images
β’ Pituitary: 85 images
β’ Total: 310 images
- Image Format: PNG/JPEG
- Image Size: 256 Γ 256 pixels
- Color Mode: RGB (3 channels)
- Data Split: ~80% Training, ~10% Validation ~10% Testing
NASNetMobile is a lightweight neural architecture search (NAS) network optimized for mobile devices while maintaining high accuracy. It was discovered through automated neural architecture search on ImageNet.
- Base Model: NASNetMobile (pre-trained on ImageNet)
- Input Shape: (224, 224, 3)
- Parameters: ~5.3M trainable parameters
- Architecture Type: Transfer Learning
- Global Average Pooling: Reduces spatial dimensions
- Dense Layer (256 units): Feature extraction with ReLU activation
- Dropout (0.5): Regularization to prevent overfitting
- Batch Normalization: Stabilizes training
- Dense Layer (128 units): Additional feature learning
- Dropout (0.3): Additional regularization
- Output Layer (4 units): Softmax activation for multi-class classification
Target Size: 224 Γ 224 pixels (NASNetMobile requirement)
# Pixel values normalized to [0, 1]
pixel_values = pixel_values / 255.0Data augmentation techniques applied to improve model generalization:
| Augmentation | Parameters | Purpose |
|---|---|---|
| Rotation | Β±15 degrees | Handle different scan orientations |
| Width Shift | Β±10% | Account for positioning variations |
| Height Shift | Β±10% | Account for positioning variations |
| Shear | 0.2 | Handle perspective distortions |
| Zoom | Β±20% | Scale invariance |
| Horizontal Flip | Yes | Mirror symmetry |
| Fill Mode | Nearest | Handle boundary pixels |
Calculated to handle class imbalance:
Class Weights:
β’ Glioma: 0.29
β’ Meningioma: 0.29
β’ No Tumor: 0.14
β’ Pituitary: 0.27
Optimizer: Adam
- Learning Rate: 0.001
Loss Function: Sparse Categorical Crossentropy
Metrics:
- Accuracy
- Precision
- Recall
- F1-Score
Batch Size: 8
Epochs: 15
Validation Split: 10% of training dataMonitor: val_loss
Patience: 8 epochs
Restore Best Weights: TrueMonitor: val_loss
Factor: 0.3
Patience: 2 epochs
Min LR: 1e-10Save Best Model: True
Monitor: val_loss- Freeze Base Model: Initial training with frozen NASNetMobile layers
- Feature Extraction: Train only custom head (15 epochs)
- Fine-Tuning: Unfreeze last 35 layers of NASNetMobile
- Full Training: Train entire model with reduced learning rate to be 0.0001 (25 epochs)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FINAL MODEL PERFORMANCE SUMMARY β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Training Accuracy: 98.3% β
β Validation Accuracy: 93.8% β
β Test Accuracy: 95.2% β
β-----------------------------------------------------------β
β Training Loss: 0.0508 β
β Validation Loss: 0.1714 β
β Test Loss: 0.2374 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Strong diagonal indicates good classification
- Minimal confusion in giloma tumor type
- Highest accuracy on "No Tumor" and "Pituitary" class (98.0%)
- Some confusion between Glioma and Meningioma (5 cases)
- Clone the Repository
git clone https://github.com/yourusername/brain-tumor-classification.git
cd brain-tumor-classification- Create Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install Dependencies
pip install -r requirements.txt-
High Accuracy Across All Classes
- The model achieves >95% accuracy for all tumor types
- Minimal false positives/negatives critical for medical applications
-
Strong Generalization
- Small gap between training (98%) and test (95%) accuracy
- Effective data augmentation prevents overfitting
-
Clinical Relevance
- High precision (0.95) reduces false alarms
- High recall (0.95) ensures tumor detection
- Balanced performance suitable for screening tool
This model is for research/educational purposes only.
-
Dataset Limitations:
- Limited to 4 classes
- Single dataset source
- Imbalanced classes
- Small size dataset
-
Edge Cases:
- May struggle with rare tumor variants
- Performance on low-quality or corrupted images not evaluated
- Multi-tumor cases not addressed
- Increase Dataset Size: Collect more diverse MRI samples
- Add More Classes: Include additional tumor types
- Performance: Improve Model performance and time
- 3D MRI Analysis: Process full 3D MRI volumes instead of 2D slices
- Tumor Segmentation: Add pixel-level tumor boundary detection
- Multi-modal Fusion: Incorporate CT, PET scans alongside MRI
- Real-time Deployment: Create web/mobile application for inference
- Clinical Integration: Develop DICOM compatibility
- Attention Mechanisms: Implement self-attention for better feature focus
- Few-shot Learning: Handle rare tumor types with limited data
- Uncertainty Quantification: Provide confidence intervals for predictions
- Multi-task Learning: Simultaneously predict tumor type, grade, and size
- Brain Tumors 256Γ256: Kaggle Dataset
- GANs for Kidney and Brain Tumors
- COVID-19 CT Scan Classification DenseNet PyTorch
- Medical Text Classification using BiLSTM, BiGRU & Conv1D
- ECG Signal Classification using RNN, GRU & LSTM
Contributions are welcome! Please follow guidelines
- This model is NOT approved for clinical diagnosis
- Always consult qualified medical professionals
- Patient privacy must be maintained at all times
- Informed consent required for any medical data usage
- All patient identifiable information must be removed
- Comply with HIPAA, GDPR, and local regulations
- Secure storage and transmission of medical images
- Model trained on limited demographic data
- May not generalize across all populations
- Continuous monitoring for bias required
- Diverse dataset collection recommended
Kaggle: @ahmedashrafhelmi
Project Link: Brain Tumor Classification Notebook



