931 943 957 Report DIP Brain Cancer Detection
931 943 957 Report DIP Brain Cancer Detection
Submitted By
Fall, 2024
1
Table of Contents
1. Introduction ............................................................................................................................. 3
2. Motivation ............................................................................................................................... 3
3. Literature Review .................................................................................................................... 3
3.1 Convolutional Neural Networks (CNNs) .......................................................................... 3
3.2 Transfer Learning ................................................................................................................. 3
3.3 U-Net Architecture ............................................................................................................... 3
3.4 Capsule Networks ................................................................................................................ 3
3.5 Hybrid Models ...................................................................................................................... 4
2
1. Introduction
Although brain cancers are relatively rare, there are few forms of cancers as deadly and aggressive than
brain cancers due to fast growth and their critical placement in the brain. Given the complexity involved
in MRI or CT scans, the interpretation tends to be by experts, leaving much room for variability among
the results obtained. On imaging techniques, we come up with systems that provide the support required
by experts like radiologists to improve efficiencies in diagnosis and accuracy. This project is concerned
with developing a modular CAD system using deep learning architectures.
Figure 1
2. Motivation
Scalability: Many hospitals in poor areas don’t have enough skilled doctors. A CAD system can
provide reliable cancer detection to everyone.
Consistency: Systems avoid errors caused by human judgment and give accurate, repeatable
results.
Future Potential: The system's design can easily be updated to work with new imaging
technologies and datasets.
3. Literature Review
3
3.5 Hybrid Models
Hybrids of deep learning with the traditional machine learning that also make use of hybrids as described by
Fabian Isensee et al. in 2020 achieve improvements in performance. Hybrid U-Net and random forest
combined brain tumor segmentation, achieved the best results on BRATS at high computational cost.
4. Problem Statement
The detection of brain cancer is still not easy due to the complication of medical images, and this requires
manual experience. The existing methods are usually dominated by computational inefficiencies or
overfitting. This work is intended to be a CAD system that uses deep learning for the detection and
classification of brain tumors from MRI/CT scans.
5. References
[1]. Pereira, S., et al. "Brain tumor segmentation using convolutional neural networks in MRI images." IEEE
Transactions on Medical Imaging, 2016.
[2]. Ronneberger, O., et al. "U-Net: Convolutional networks for biomedical image segmentation." Medical
Image Computing and Computer-Assisted Intervention – MICCAI 2015. Springer, 2015.
[3]. Afshar, P., et al. "Capsule networks for brain tumor classification based on MRI images and coarse
tumor boundaries." Expert Systems with Applications, 2019.
[4]. Afshar, P., et al. "Using ResNet for brain tumor classification on MRI images." Proceedings of the IEEE
International Symposium on Biomedical Imaging, 2018.
[5]. Isensee, F., et al. "Automated design of deep learning methods for biomedical image segmentation."
Nature Methods, 2020.
Solution:
The solution is the use of CNN for classifying brain MRI images into two categories: "tumor" and "no
tumor". The steps in this process are:
Data Preprocessing: Resize the images to 128x128 pixels, normalize them and apply one-hot
encoding of labels.
Model Architecture: The model has three convolutional layers that are used for feature extraction,
max-pooling layers for downsampling, and dense layers for classification. Dropout is applied to
prevent overfitting.
Training: The model was trained on categorical cross-entropy loss with the Adam optimizer for 20
Epochs.
Prediction: The model predicts whether the new MRI image contains a tumor or not.
4
Code:
Import Libraries:
import cv2
import numpy as np
import os
from sklearn.model_selection import train_test_split
from tensorflow.keras.utils import to_categorical
import matplotlib.pyplot as plt
Define Constants and Load Data:
# Define constants
IMG_SIZE = 128 # Resize all images to 128x128
CATEGORIES = ["no", "yes"] # Subfolders for classes (no tumor, tumor)
5
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.3,
random_state=42)
X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5,
random_state=42)
6
Evaluate Model on Test Set:
# Evaluate model on the test set
test_loss, test_accuracy = model.evaluate(X_test, y_test, verbose=1)
print(f"Test Accuracy: {test_accuracy * 100:.2f}%")
# Accuracy plot
plt.subplot(1, 2, 1)
plt.plot(history.history['accuracy'], label='Train Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.title('Model Accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
# Loss plot
plt.subplot(1, 2, 2)
plt.plot(history.history['loss'], label='Train Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.title('Model Loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
7
Upload New MRI Image for Prediction with Probability:
# Upload New MRI Image for Prediction with Probability
# Preprocess the image: resize it to the same size used for training (128x128)
img = image.load_img(img_path, target_size=(IMG_SIZE, IMG_SIZE))
img_array = image.img_to_array(img) # Convert to array
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
img_array = img_array / 255.0 # Normalize the image
8
Output:
If tumor is present,
If there is no tumor,
9
For running this program, we used Google Colab because when training the Model it takes GPU as well, my
advice is to upload the brain_tumor_dateset.zip in Google drive then unzipped it first using this given code
below:
import zipfile
import os
10