Deep Learning Dynamics: CNN Model for Brain Tumor Detection
- Aastha Thakker
- Oct 29, 2025
- 6 min read

I recently finished a project that tackles one of the most important problems in neuro-oncology: the categorization of brain tumors. It combines deep learning and medical imaging. We developed a strategy that uses convolutional neural networks (CNNs) to accurately diagnose various brain tumor types from MRI data. This is a strategy that uses convolutional neural networks (CNNs) to accurately diagnose various brain tumor types from MRI data.
Why Brain Tumor Classification Matters
Every minute counts when it comes to brain tumor diagnosis. Traditional methods rely on expert radiologists manually interpreting complex MRI scans — a process that’s time-consuming and prone to human variability.
But what if we could supercharge this process with artificial intelligence?

This is where AI-powered classification systems can serve as valuable supporting tools for medical professionals.
Here is the link to code for doing things practically: https://github.com/AasthaThakker/AI-ML-Project.
Understanding Our Dataset
Our project utilized a comprehensive dataset sourced from Kaggle, comprising 15,000 MRI images categorized into three major types of brain tumors. This dataset was pivotal in building a robust classification model and allowed for a detailed exploration of the unique characteristics of each tumor type:
Gliomas:
Gliomas arise from glial cells, which are essential for supporting and insulating neurons. These tumors represent the most common type of brain tumor and are particularly challenging due to their aggressive and infiltrative nature. Gliomas often spread diffusely throughout brain tissue, making treatment complex and requiring precise diagnostic tools.
Meningiomas:
These tumors develop in the meninges, the protective membranes surrounding the brain and spinal cord. Meningiomas tend to grow more slowly than gliomas, but their presence can exert significant pressure on surrounding brain tissue, leading to neurological symptoms. Despite their typically benign nature, their location often poses surgical challenges.
Pituitary Tumors:
Found in the pituitary gland, these tumors interfere with the gland’s hormonal regulation, potentially causing a range of endocrine disorders. Though generally less invasive than gliomas, their impact on the body’s hormonal balance can lead to serious systemic effects.
Data Preparation
Initial Data Organization
Our first step involved organizing the 15,000 images into a structured format. I created a pandas Data Frame that stored the image paths and their corresponding labels, making it easier to handle the data programmatically.

Strategic Data Splitting
The data-splitting process was more nuanced than simple random division. I implemented a stratified split using sci-kit-learn’s StratifiedShuffleSplit, ensuring that each subset maintained the same proportion of tumor types as the original dataset. This resulted in:
Training set: 10,500 images (70%)
Validation set: 2,250 images (15%)
Test set: 2,250 images (15%)
The stratification was crucial because it prevented any accidental bias in our data distribution. For instance, if one tumor type was underrepresented in the training set, the model might not learn its features adequately.




Advanced-Data Augmentation Techniques
Our data augmentation pipeline was designed to create realistic variations of our MRI scans while preserving their medical validity. Using Keras’ ImageDataGenerator, we implemented:
Rotation transformations: Images were randomly rotated within a 40-degree range, simulating different head positions during MRI scanning.
Width and height shifts: We allowed shifts up to 20% of the image dimensions, accounting for different tumor positions within the scan.
Horizontal flipping: This helped the model learn that tumors can appear on either side of the brain.
Careful fill mode selection: We used ‘nearest’ neighbor filling for transformed areas to maintain image integrity.
These augmentations were applied in real-time during training, effectively increasing our dataset size without physically storing duplicate images.

Image Pre-processing Pipeline
Our pre-processing pipeline involved several critical steps:
Standardization: All images were resized to 128x128 pixels, balancing preserving important details and computational efficiency. We maintained the RGB colour channels as they contained valuable diagnostic information.
Normalization: Pixel values were scaled to the range [0,1] by dividing by 255. This normalization step is crucial for deep learning models as it helps achieve faster convergence during training and ensures consistent processing across all images.
Batch Processing: We set up data generators to create batches of 32 images simultaneously, optimizing memory usage during training while ensuring efficient model updates.
The Architecture: Building Our CNN
This CNN architecture was carefully designed to capture both fine details and broader patterns in the MRI scans.


Here’s a detailed breakdown of our model structure:'
Input Layer
The network accepts 128x128x3 images (RGB format), providing sufficient resolution for tumour detection while remaining computationally efficient.
Feature Extraction Layers
1. Initial Convolution Block:
First convolutional layer with 32 filters, capturing basic features like edges and textures
ReLU activation to introduce non-linearity
MaxPooling to reduce spatial dimensions while retaining important features
2. Deeper Feature Extraction:
Additional convolutional layers with increasing filter counts (64, 128)
Each followed by ReLU activation and MaxPooling
This progression allows the network to learn increasingly complex features
Classification Layers
1. Flattening Layer: Converts the 3D feature maps to a 1D vector
2. Dense Layers:
The first dense layer with 512 units and ReLU activation
Dropout layer (0.5 rate) to prevent overfitting
Final dense layer with 3 units (one for each tumour type) and SoftMax activation
Training Process and Optimization
The training process was carefully monitored and optimized:
1. Loss Function: We used categorical cross-entropy, appropriate for our multi-class classification task. (Cross-entropy measures the difference between actual and predicted probabilities, penalizing confident but incorrect predictions.)
2. Optimizer: Adam optimizer with a learning rate of 0.001, providing adaptive learning rate adjustments. (Optimizers adjust the model’s parameters (weights and biases) during training to minimize the loss function, helping the model learn patterns in the data effectively.)
3. Training Schedule:
Batch size of 32 images
Training continued for 6 epochs
Early stopping was implemented to prevent overfitting
Model checkpoints saved the best-performing weights

Results and Performance Evaluation
The CNN model achieved impressive performance metrics in classifying brain tumors into three categories: gliomas, meningiomas, and pituitary tumors. Below is a detailed breakdown of the results:
Class-Wise Metrics:
1. Brain Glioma:
Precision: 0.99 — Indicates the model’s ability to correctly identify glioma cases without false positives.
Recall: 0.99 — This shows the model’s effectiveness in identifying all actual glioma cases.
F1-Score: 0.99 — The harmonic mean of precision and recall, demonstrating balanced performance for this class.
2. Brain Meningioma:
Precision: 0.99 — High precision reflects accurate identification of meningiomas.
Recall: 0.91 — Slightly lower recall suggests a few meningioma cases were misclassified.
F1-Score: 0.95 — The combination of high precision and good recall results in strong overall performance.
3. Brain Tumour (Pituitary Tumours):
Precision: 0.92 — Indicates reliable detection of pituitary tumour cases, though slightly lower compared to other classes.
Recall: 1.00 — Perfect recall highlights that all pituitary tumour cases were correctly identified.
F1-Score: 0.96 — Reflects excellent overall performance for this class.
Overall Accuracy:
The model achieved an accuracy of 96% across the entire test set of 2,250 images, signifying its robust ability to generalize and classify unseen data.


Challenges and Solutions
Throughout the project, we encountered several challenges:
1. Class Imbalance: Initially, some tumour types were represented more than others. We addressed this through stratified sampling and careful data augmentation.
2. Overfitting Concerns: Early versions of the model showed signs of overfitting. We successfully combated this through:
Dropout layers
Data augmentation
Early stopping
Regular monitoring of validation metrics
3. Image Quality Variation: MRI scans came with varying qualities and contrasts. Our pre-processing pipeline helped standardize these variations while preserving important diagnostic features.
Looking Forward to Future Improvements
While our model shows promising results, several avenues for improvement exist:
Dataset Expansion: Including more rare tumour types and variants could make the model more comprehensive.
Architecture Refinements:
Experimenting with more advanced architectures like ResNet or DenseNet
Implementing attention mechanisms for better feature focus
Exploring transfer learning with pre-trained models
Clinical Integration:
Developing an intuitive interface for medical professionals
Incorporating explainable AI techniques
Conducting extensive clinical validation studies
Conclusion
This project demonstrates the powerful potential of deep learning in medical imaging. Our CNN-based system achieved high accuracy in classifying brain tumours, potentially offering valuable assistance to medical professionals in their diagnostic work. The success of this project not only validates the technical approach but also points toward a future where AI can meaningfully support medical decision-making.
The combination of careful data preparation, thoughtful architecture design, and rigorous validation has resulted in a robust system that could serve as a stepping stone toward more advanced medical imaging applications. As we continue to refine and improve such systems, the goal remains clear: to develop tools that can assist healthcare providers in making faster, more accurate diagnoses for better patient outcomes.
Reference link for more deeper understanding: https://journalofbigdata.springeropen.com/articles/10.1186/s40537-021-00444-8
Go ahead and make your own model!



Comments