Deep Learning Dynamics: CNN Models for Brain Tumour Detection

Deep Learning Dynamics: CNN Models for Brain Tumour Detection

I recently finished a project that tackles one of the most important problems in neuro-oncology: the categorization of brain tumours. It combines deep learning and medical imaging. We developed a strategy that uses convolutional neural networks (CNNs) to accurately diagnose various brain tumour types from MRI data. This is a strategy that uses convolutional neural networks (CNNs) to accurately diagnose various brain tumour types from MRI data.

Why Brain Tumour Classification Matters

Every minute counts when it comes to brain tumour 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 tumours. This dataset was pivotal in building a robust classification model and allowed for a detailed exploration of the unique characteristics of each tumour type:

  1. Gliomas: Gliomas arise from glial cells, which are essential for supporting and insulating neurons. These tumours represent the most common type of brain tumour 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.
  2. Meningiomas: These tumours 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.
  3. Pituitary Tumours: Found in the pituitary gland, these tumours 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 tumour 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 tumour type was underrepresented in the training set, the model might not learn its features adequately.

Data Visualization

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:

  1. Rotation transformations: Images were randomly rotated within a 40-degree range, simulating different head positions during MRI scanning.
  2. Width and height shifts: We allowed shifts up to 20% of the image dimensions, accounting for different tumour positions within the scan.
  3. Horizontal flipping: This helped the model learn that tumours can appear on either side of the brain.
  4. Careful fill mode selection: We used ‘nearest’ neighbour 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:

  1. 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.
  2. 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.
  3. 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.

Convolutional Neural Network (CNN) architecture diagram showing the layer structure, including convolutional layers, pooling layers, and fully connected layers used for brain tumour classification.

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 firstdense 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

We monitored both training and validation metrics in real-time, keeping observation of accuracy and loss curves to ensure proper learning progression.

Results and Performance Evaluation

The CNN model achieved impressive performance metrics in classifying brain tumours into three categories: gliomas, meningiomas, and pituitary tumours. 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.

Confusion matrix visualization showing the model’s classification performance across the three tumour types (Glioma, Meningioma, Pituitary).

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:

  1. Dataset Expansion: Including more rare tumour types and variants could make the model more comprehensive.
  2. 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
  3. 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!

KUNJ SHAH

Aspiring Cybersecurity Expert | TryHackMe Enthusiast | C++ & Python Developer | AI Prompt Engineer | Student Ambassador at Blackbox.ai | Computer Science Student at INDUS University

3 个月

Love this

要查看或添加评论,请登录

Aastha Thakker的更多文章

  • Reverse Engineering Essentials?-?1

    Reverse Engineering Essentials?-?1

    Hey everyone! In our last blog, we talked about what “engineering” really means, and how “reverse engineering” fits…

    2 条评论
  • Forward & Reverse Engineering

    Forward & Reverse Engineering

    How frequently do you hear the term “reverse engineering” in the cyber world? Often, right! To understand reverse…

  • AWS Practical — 1

    AWS Practical — 1

    Alright, let’s move from theory to practical! We’ve discussed the breadth of AWS capabilities, and now it’s time to get…

  • SOC: Human, Automation & AI Teaming to Beat Alert?Fatigue

    SOC: Human, Automation & AI Teaming to Beat Alert?Fatigue

    You’re stuck in a digital panic room. Every notification is a mini-heart attack.

  • MANETs: How Devices Create Their Own Social Networks

    MANETs: How Devices Create Their Own Social Networks

    In an era where our homes are getting smarter and our devices are increasingly interconnected, there’s a pressing…

    2 条评论
  • Satellite Hacking: Space?Wars

    Satellite Hacking: Space?Wars

    Hey there! How are you able to read this post? Is it the internet? Of course! But what’s the backbone of this…

    1 条评论
  • Digital Forensics and Anti-forensics

    Digital Forensics and Anti-forensics

    Hey Everyone! Just like our previous dive into purple teaming, this blog lays the groundwork for understanding both…

    2 条评论
  • Gen AI vs. Agentic AI

    Gen AI vs. Agentic AI

    Hey Everyone! Another AI blog post! (I can hear your eyes rolling from here.) But wait — before you close this tab…

    7 条评论
  • Purple Teaming: Turning Frenemies into Allies

    Purple Teaming: Turning Frenemies into Allies

    Remember Tom and Jerry? Those two were the ultimate frenemies. When they were fighting, they’d wreck the entire house.

    6 条评论
  • Cloud Computing with AWS: Basics

    Cloud Computing with AWS: Basics

    Hey Everyone! Remember our last blog about cloud computing? You know, where we learned about all those cool benefits…

    4 条评论

社区洞察

其他会员也浏览了