This project implements and compares multiple deep learning architectures for classifying brain tumor MRI images into four categories: Glioma, Meningioma, No Tumor, and Pituitary Tumor. The project demonstrates both custom CNN architecture design and transfer learning approaches using state-of-the-art pre-trained models.
Develop and evaluate multiple CNN models for accurate brain tumor classification from MRI scans, comparing performance across different architectural approaches to identify optimal solutions for medical image classification.
Source: Brain Tumor MRI Dataset from Kaggle
Dataset Statistics:
- Total Images: ~7,000+ MRI scans
- Training Set: ~5,700 images
- Testing Set: ~1,300 images
- Classes: 4 (Glioma, Meningioma, No Tumor, Pituitary)
- Format: JPG/PNG images
- Characteristics: Varied image sizes, slight class imbalance
- Architecture: Custom-designed Convolutional Neural Network
- Input Size: 128×128 pixels
- Layers: Multiple Conv2D, MaxPooling2D, Dense layers with Dropout
- Approach: Built from scratch without pre-trained weights
- Highlights:
- Lightweight architecture
- Faster training and inference
- Lower computational requirements
- Class weight balancing for handling imbalance
- Architecture: VGG16 with custom classification head
- Input Size: 224×224 pixels
- Approach: Two-phase training
- Phase 1: Frozen base model (feature extraction)
- Phase 2: Fine-tuning top layers
- Highlights:
- Deep feature extraction (16 layers)
- Pre-trained on ImageNet
- Proven performance on medical imaging tasks
- Architecture: InceptionV3 with custom classification layers
- Input Size: 224×224 pixels
- Approach: Multi-scale feature extraction with inception modules
- Highlights:
- Efficient multi-scale processing
- Reduced parameters compared to VGG
- Advanced architectural design with parallel pathways
- Architecture: DenseNet121 with custom top layers
- Input Size: 224×224 pixels
- Approach: Dense connections between layers
- Highlights:
- Feature reuse through dense connections
- Parameter efficient architecture
- Better gradient flow for deeper networks
- Excellent for limited medical data
Comprehensive comparison notebook that:
- Loads all four trained models from Google Drive
- Evaluates on the same test dataset
- Generates performance metrics and visualizations
- Provides detailed per-class analysis
- Creates confusion matrices for all models
- Compares architectural characteristics
Evaluation Metrics:
- Test Accuracy
- Test Loss
- Precision, Recall, F1-Score (per class)
- Confusion Matrices
- Parameter Count Comparison
- Framework: TensorFlow 2.x / Keras
- Language: Python 3.12
- Libraries:
- NumPy, Pandas (data manipulation)
- Matplotlib, Seaborn (visualization)
- Scikit-learn (metrics)
- Kaggle API (dataset download)
- Environment: Google Colab (GPU-accelerated)
- Google Colab account (recommended) or local Python environment
- Kaggle account and API credentials (
kaggle.json) - Google Drive (for model storage)
-
Clone the repository
git clone <repository-url> cd <project-name>
-
Upload to Google Colab
- Upload the notebooks to your Google Colab environment
- Mount Google Drive for model storage
-
Setup Kaggle API
- Download
kaggle.jsonfrom your Kaggle account settings - Upload it to the Colab environment
- The notebooks will automatically configure Kaggle credentials
- Download
-
Run Notebooks
- Execute each model notebook sequentially
- Models will be saved to Google Drive
- Run comparison notebook after all models are trained
Each model follows a similar training pipeline:
- Data Loading: Download dataset via Kaggle API
- Preprocessing:
- Image resizing (128×128 or 224×224)
- Normalization/preprocessing specific to each architecture
- Data augmentation (rotation, shifts, flips, zoom)
- Class Imbalance Handling: Computed class weights
- Training:
- Train/validation split (typically 85/15)
- Early stopping and learning rate reduction
- Model checkpointing
- Evaluation:
- Test set evaluation
- Confusion matrix generation
- Per-class metrics analysis
- Model Saving: Save trained models to Google Drive
Custom CNN:
- Fastest training and inference
- Smallest model size
- Lower computational requirements
- May have lower accuracy than transfer learning models
VGG16:
- Strong feature extraction
- High accuracy on medical images
- Large number of parameters
- Higher memory requirements
InceptionV3:
- Multi-scale feature extraction
- More parameter efficient than VGG
- Good balance of accuracy and efficiency
DenseNet121:
- Excellent feature reuse
- Parameter efficient
- Strong performance with limited data
- Good gradient flow
| Scenario | Recommended Model | Reason |
|---|---|---|
| Production Deployment | VGG16 or DenseNet | Highest accuracy and reliability |
| Resource-Constrained | Custom CNN | Lightweight, fast inference |
| Mobile/Edge Devices | Custom CNN or DenseNet | Smaller size, efficient |
| Research/Development | All models | Comparative analysis |
Applied augmentation strategies:
- Horizontal flipping
- Rotation (±10-20 degrees)
- Width/Height shifts (5-10%)
- Zoom (5-10%)
- Brightness adjustments (model-specific)
- Computed balanced class weights
- Applied during model training
- Ensures fair representation of minority classes
- Improves model generalization
- Preprocessing: Consistent image normalization
- Validation: Stratified splits to maintain class distribution
- Evaluation: Focus on recall to minimize false negatives
- Interpretability: Confusion matrices for clinical understanding
Common Hyperparameters:
- Optimizer: Adam
- Loss Function: Categorical Crossentropy
- Metrics: Accuracy, Precision, Recall
- Batch Size: 32
- Epochs: 15-20 (with early stopping)
- Validation Split: 15-20%
Transfer Learning Specifics:
- Phase 1: Frozen base, learning rate ~1e-3
- Phase 2: Unfrozen top layers, learning rate ~5e-5
- Fine-tuning: Last 15-24 layers unfrozen
All notebooks include:
- Training/Validation accuracy and loss curves
- Confusion matrices with heatmaps
- Per-class precision, recall, F1-scores
- ROC-AUC scores (where applicable)
- Comparative bar charts
This is an academic project for Deep Learning coursework.
This project is part of academic coursework. Dataset is licensed under CC0-1.0 from Kaggle.
Deep Learning Assignment - Brain Tumor Classification SLIIT - SE4050 Deep Learning Module
- Dataset: Masoud Nickparvar
- TensorFlow/Keras documentation and community
- Pre-trained model weights from ImageNet
- Google Colab for providing free GPU resources
Note: This project is for educational purposes as part of the SE4050 Deep Learning module at SLIIT. All models and results are based on academic research and should not be used for actual medical diagnosis without proper validation and regulatory approval.