This project focuses on detecting brain tumors from MRI images using a Convolutional Neural Network (CNN) built with TensorFlow and Keras. The model is trained on a dataset consisting of images categorized into four classes: Glioma, Meningioma, NoTumor, and Pituitary.
- Introduction
- Approach
- Categories
- CNN Model
- Data Preprocessing
- Training the Model
- Evaluating the Model
- Prediction
- Results
- Installation
- Usage
- Contributing
Brain tumors are abnormal growths of cells in the brain that can be life-threatening. Accurate detection from MRI images is crucial for timely and effective treatment. This project aims to classify MRI images into four categories:
- Glioma
- Meningioma
- NoTumor
- Pituitary
We use a Convolutional Neural Network (CNN) due to its effectiveness in handling visual data. The CNN model is trained to learn the intricate features of MRI images and classify them into the aforementioned categories.
- Glioma: A type of tumor that occurs in the brain and spinal cord.
- Meningioma: A tumor that arises from the meninges, the membranes that surround the brain and spinal cord.
- NoTumor: MRI images that do not show any signs of a tumor.
- Pituitary: Tumors that occur in the pituitary gland, which is located at the base of the brain.
The CNN model architecture includes:
- Data Augmentation: Increases the diversity of the training dataset.
- Rescaling: Normalizes pixel values to the range [0, 1].
- Convolutional Layers: Extracts features using filters.
- MaxPooling Layers: Reduces the spatial dimensions of the feature maps.
- Dropout Layer: Prevents overfitting.
- Flatten Layer: Converts 2D matrices to 1D vectors.
- Dense Layers: Performs classification based on the extracted features.
The CNN model is built using TensorFlow and Keras. The model architecture includes multiple convolutional layers followed by max-pooling layers and dense layers for classification.
The model is defined and trained twice, utilizing different techniques to enhance accuracy and performance:
-
Initial Model Training: The initial model is defined with multiple convolutional layers, max-pooling layers, and dense layers. It is compiled and trained on the dataset to get a baseline accuracy.
-
Enhanced Model Training: A second model is then defined and trained using advanced data augmentation techniques (such as random flipping, rotation, and zoom) and hyperparameter tuning. This step aims to improve the initial model's accuracy and robustness.
The dataset is split into training and validation sets with an 80-20 ratio. Data augmentation techniques such as random flipping, rotation, and zoom are applied to the training data to improve the model's generalization capability.
- Load and preprocess the dataset.
- Split the dataset into training and validation sets.
- Define the initial CNN model architecture.
- Compile and train the initial model using the Adam optimizer and Sparse Categorical Crossentropy loss function.
- Define and train the enhanced model with improved data augmentation and hyperparameters.
The model's performance is evaluated using training and validation accuracy and loss metrics. Plots of accuracy and loss over epochs are created to visualize the training process.
The trained model is used to make predictions on new MRI images. The model outputs the predicted class along with confidence scores.
- The initial model achieved an accuracy of
97.85%on the training set and93.45%on the validation set. - The enhanced model achieved an accuracy of
98.53%on the training set and95.63%on the validation set after100epochs. - The model demonstrated high confidence and accuracy in classifying MRI images into the correct categories.
-
Clone the repository:
git clone https://github.com/your-username/brain-tumor-detection.git cd brain-tumor-detection -
Mount Google Drive in Colab:
from google.colab import drive drive.mount('/content/drive')
-
Install the required libraries:
pip install tensorflow pip install matplotlib
- Load and preprocess the MRI image dataset.
- Train the CNN model on the dataset.
- Evaluate the model's performance.
- Use the model to make predictions on new MRI images.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.