Brain Tumor Detection Using Convolutional Neural Networks.
Building a detection model using a convolutional neural network in Tensorflow & Keras.
Used a brain MRI images data founded on Kaggle. You can find it here.
About the data:
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 and the folder no contains 98 Brain MRI Images that are non-tumorous.
Note: sometimes viewing IPython notebooks using GitHub viewer doesn't work as expected, so you can always view them using nbviewer.
Why did I use data augmentation?
Since this is a small dataset, There wasn't enough examples to train the neural network. Also, data augmentation was useful in taclking the data imbalance issue in the data.
Further explanations are found in the Data Augmentation notebook.
Before data augmentation, the dataset consisted of:
155 positive and 98 negative examples, resulting in 253 example images.
After data augmentation, now the dataset consists of:
1085 positive and 980 examples, resulting in 2065 example images.
Note: these 2065 examples contains also the 253 original images. They are found in folder named 'augmented data'.
For every image, the following preprocessing steps were applied:
The data was split in the following way:
This is the architecture that I've built:
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:
Why this architecture?
Firstly, I applied transfer learning using a ResNet50 and vgg-16, but these models were too complex to the data size and were overfitting. Of course, you may get good results applying transfer learning with these models using data augmentation. But, I'm using training on a computer with 6th generation Intel i7 CPU and 8 GB memory. So, I had to take into consideration computational complexity and memory limitations.
So why not try a simpler architecture and train it from scratch. And it worked :)
The model was trained for 24 epochs and these are the loss & accuracy plots:
The best validation accuracy was achieved on the 23rd iteration.
Now, the best model (the one with the best validation accuracy) detects brain tumor with:
88.7% accuracy on the test set.
0.88 f1 score on the test set.
These resutls are very good considering that the data is balanced.
Performance table of the best model:
Validation set | Test set | |
---|---|---|
Accuracy | 91% | 89% |
F1 score | 0.91 | 0.88 |
What's in the files?
from tensorflow.keras.models import load_model
best_model = load_model(filepath='models/cnn-parameters-improvement-23-0.91.model')
Contributes are welcome!
Thank you!