Brain Tumor Segmentation Using Deep Learning

Sayanb
4 min readJul 1, 2021

--

Introduction:

In this blog, you will see an example of a brain tumor detector using a convolutional neural network.

Domain-related Background:

A brain tumor is a mass or growth of abnormal cells in the brain. Brain tumors can be cancerous (malignant) or noncancerous (benign).

One of the tests to diagnose brain tumor is magnetic resonance imaging (MRI).

The deep learning techniques and methods have performed well on image classification and supervised machine learning, as reported in recent research papers. Brain tumor has various classes, which include glioma, meningioma and pituitary tumors. Brain tumor is further classified as benign or low-grade I and II and malignant tumor, or high-grade III and IV. The following paragraphs thoroughly explain the recent research into brain tumor analysis. Table 1 shows the various data sources and their acquisition methods.

The Dataset:

A brain MRI images dataset founded on Kaggle.

The dataset contains 2 folders: yes and no which contains 253 Brain MRI Images. The folder yes contains 155 Brain MRI Images that are tumorous (malignant) and the folder no contains 98 Brain MRI Images that are non-tumorous (benign).

Meaning that 61% (155 images) of the data are positive examples and 39% (98 images) are negative.

Data Preprocessing:

For every image, the following preprocessing steps were applied:

  1. Crop the part of the image that contains only the brain (which is the most important part of the image): you can read more about the cropping technique to find the extreme top, bottom, left and right points of the brain in this blog Finding extreme points in contours with OpenCV.
  2. Resize the image to have a shape of (240, 240, 3)=(image_width, image_height, number of channels): because images in the dataset come in different sizes. So, all images should have the same shape to feed it as an input to the neural network.
  3. Apply normalization: to scale pixel values to the range 0–1.

Data Split:

The data was split in the following way:

70% of the data for training.

15% of the data for validation (development).

15% of the data for testing.

The Neural Network Architecture:

Understanding the architecture:

Each input x (image) has a shape of (240, 240, 3) and is fed into the neural network. And, it goes through the following layers:

  1. A Zero Padding layer with a pool size of (2, 2).
  2. A convolutional layer with 32 filters, with a filter size of (7, 7) and a stride equal to 1.
  3. A batch normalization layer to normalize pixel values to speed up computation.
  4. A ReLU activation layer.
  5. A Max Pooling layer with f=4 and s=4.
  6. A Max Pooling layer with f=4 and s=4, same as before. I’ve added another pooling layer in order to have less computation cost.
  7. A Flatten layer in order to flatten the 3-dimensional matrix into a one-dimensional vector.
  8. A Dense (output unit) fully connected layer with one neuron with a sigmoid activation (since this is a binary classification task).

Training The Model:

Why we used more than one Epoch?

I know it doesn’t make sense in the starting that — passing the entire dataset through a neural network is not enough. And we need to pass the full dataset multiple times to the same neural network. But keep in mind that we are using a limited dataset and to optimise the learning and the graph we are using Gradient Descent which is an iterative process. So, updating the weights with single pass or one epoch is not enough.

From the plot of loss, we can see that the model has comparable performance on both train and validation datasets If these parallel plots start to depart consistently, it might be a sign to stop training at an earlier epoch.

The model was trained for 19 epochs and these are the loss & accuracy plots:

The training and validation loss across the epochs

The training and validation accuracy across the epochs

As shown in the figure, the model with the best validation accuracy (which is 91%) was achieved on the 19th epoch.

Results:

Now, the best model (the one with the best validation accuracy) detects brain tumor with:

--

--