This repository contains an end-to-end Computer Vision pipeline designed to automatically detect brain tumors from MRI scans. Built using the CRISP-DM methodology, this project leverages Deep Learning and Transfer Learning (Xception Architecture) to serve as an AI-assisted clinical decision-support tool, improving diagnostic speed and reliability.
Dataset: Brain MRI Images Dataset (Mendeley Data) (~10,093 images)
Brain tumor diagnosis is time-sensitive and highly dependent on radiologist expertise. This project bridges the gap between raw medical imaging and operational healthcare delivery by:
- Reducing Diagnostic Fatigue: Providing a highly reliable "first-pass" screening tool to assist medical professionals.
- Minimizing False Negatives: Optimizing the model for high Recall (Sensitivity), ensuring that actual tumors are rarely missed (only a ~3.5% False Negative rate).
- Maximizing Efficiency: Utilizing Transfer Learning to achieve state-of-the-art accuracy without the massive computational overhead of training a Deep CNN from scratch.
While NLP models are fundamentally designed to guess the next word in a sequence, this Computer Vision architecture is built to mathematically deconstruct, interpret, and understand the physical world. It requires a higher degree of spatial multidimensionality. The raw code is available in the repository, but the strategic philosophy behind the model building is what makes it highly effective.
A vision model is only as robust as the environment it’s trained in. We didn't just feed the network data; we aggressively transformed it.
- Perfectly Balanced Dataset: The dataset contains 10,093 images with a near 50/50 split between "Tumor" and "No Tumor," eliminating the need for synthetic oversampling (SMOTE).
- Aggressive Augmentation: Applied random horizontal flips, rotations (10%), and zooming (10%) on the fly. By forcing the model to interpret augmented realities, we ensured it learned true spatial invariance across different MRI cross-sections (Axial, Sagittal, Coronal) rather than just memorizing pixel patterns.
- Pipeline Optimization: Utilized
tf.data.AUTOTUNE, caching, and prefetching to eliminate I/O bottlenecks during GPU training.
Rather than throwing layers at a GPU and hoping for convergence, we utilized the Xception model (pre-trained on ImageNet) as our architectural foundation:
- The Frozen Backbone: We locked the 20.8 million parameters of the base model to act as a highly optimized feature extractor, immediately capable of detecting low-level edges, contrasts, and hyperintense masses without retraining.
- The Custom Classification Head: We engineered a custom top layer utilizing Global Average Pooling and aggressive Dropout (0.2) to ruthlessly prune weak connections and prevent overfitting. It concludes with a Dense Sigmoid layer for precise binary classification.
- High-Efficiency Convergence: By freezing the backbone, only 2,049 parameters were actually trained, allowing for rapid convergence while maintaining a lean computational footprint.
In advanced Computer Vision, a flat "accuracy" percentage is a vanity metric. The architecture was rigorously evaluated against a strictly unseen test set of 1,816 images, focusing on clinical implications:
| Metric | Score | Clinical Implication |
|---|---|---|
| Test Accuracy | 96.81% | Highly reliable overall classification capability. |
| Recall (Tumor) | 0.96 | Caught 96% of all actual tumors (Low False Negative Rate). |
| Precision (Tumor) | 0.97 | When the model flags a tumor, it is correct 97% of the time. |
| F1-Score | 0.97 | Perfectly balanced model; no bias towards the healthy class. |
Note: The model successfully distinguished complex healthy anatomical structures (like eye sockets and ventricles) from pathological masses, proving its robustness against critical false positives.
To transition this prototype into a deployment-ready clinical application, the next phases include:
- Explainable AI (XAI): Implementing Grad-CAM heatmaps to visually highlight the exact region of the MRI driving the model's prediction, building crucial physician trust.
- Multiclass Segmentation: Expanding the architecture to classify specific tumor types (e.g., Glioma, Meningioma, Pituitary).
- Flask Web Deployment: Wrapping the
.kerasmodel in a secure, custom Flask application for easy MRI uploads and real-time inference, providing a more robust architectural foundation than standard dashboarding tools.
- Language: Python
- Deep Learning: TensorFlow 2.x, Keras
- Computer Vision: OpenCV, Matplotlib (for visualization)
- Data Processing: NumPy, Scikit-Learn
- Clone the repository:
git clone [https://github.com/yourusername/brain-tumor-detection-cv.git](https://github.com/yourusername/brain-tumor-detection-cv.git) cd brain-tumor-detection-cv - Install the required dependencies:
pip install tensorflow numpy matplotlib scikit-learn seaborn
- Run the Notebook: Open the Jupyter Notebook to view the step-by-step data pipeline, model training, and visual evaluations.
Femi James Data & Business Analyst | Integrated AI Specialist