This repository contains a deep learning model for brain tumor segmentation from MRI images using a U-Net architecture. The model is trained on the LGG MRI Segmentation dataset from Kaggle.
The project implements a U-Net model to segment brain tumors from MRI scans. The model takes MRI images as input and outputs a binary mask indicating the presence and location of tumors.
The model uses the LGG MRI Segmentation dataset from Kaggle.
- Contains 3,929 MRI images in TIFF format with corresponding masks
- Masks are binary (0 for no tumor, 1 for tumor present)
The data preprocessing pipeline includes:
- Downloading and extracting the dataset from Kaggle
- Organizing the data into a pandas DataFrame with columns:
- patient_id
- image_path
- mask_path
- mask (binary indicator)
- Splitting the data into training, validation, and test sets.
- Creating a custom data generator (
BrainTumorGenerator) that:- Loads images and masks
- Resizes them to 256x256 pixels
The model uses a U-Net architecture with the following components:
Encoder (Downsampling Path):
- 3 levels of convolutional blocks (Conv2D + Conv2D + MaxPooling2D)
- Number of filters increases from 64 to 256
Bottleneck:
- Two convolutional layers with 512 filters
Decoder (Upsampling Path):
- 3 levels of upsampling blocks (UpSampling2D + concatenation + Conv2D + Conv2D)
- Skip connections from corresponding encoder levels
- Number of filters decreases from 256 to 64
Output:
- Final 1x1 convolution with sigmoid activation for binary segmentation
The model was trained with:
- Optimizer: Adam
- Loss function: Binary crossentropy
- Batch size: 16
- Image size: 256x256
- Callbacks:
- Early stopping (patience=3)
- Model checkpointing (saves best model)
The model achieved the following performance:
- Validation Accuracy: 99.41%
- Test Accuracy: 99.10%
The model demonstrates excellent performance in segmenting brain tumors from MRI images, with high accuracy on both validation and test sets.
To run this project, you'll need:
- numpy
- pandas
- opencv
- pillow
- matplotlib
- scikit-learn
- tensorflow
- kaggle (for dataset)