This project implements a deep learning model for brain tumor segmentation using the BraTS2020 dataset. The model processes multi-modal MRI scans to identify and segment different types of brain tumors.
The project uses the BraTS2020_TrainingData dataset, which includes the following MRI modalities:
- T1-weighted (T1)
- T2-weighted (T2)
- T1 with contrast enhancement (T1ce)
- Fluid Attenuated Inversion Recovery (FLAIR)
All required dependencies are listed in the requirements.txt
file. To install them, run:
pip install -r requirements.txt
The preprocessing pipeline includes the following steps:
- Loading and scaling of multi-modal MRI images (T1, T2, T1ce, FLAIR)
- Loading and processing of segmentation masks
- Combining multiple modalities into a single 4-channel image
- Cropping images and masks to a specified region of interest
- One-hot encoding of segmentation masks
- Conversion to PyTorch tensors
- Saving processed data as PyTorch tensor files
The BrainTumorDataset
class is implemented to facilitate data loading during training. It inherits from PyTorch's Dataset
class and provides methods for accessing the preprocessed image and mask pairs.
The training process includes:
- Data loading using
DataLoader
- Model optimization using a combination of Dice loss and Focal loss
- Training and validation loops
- Logging of training and validation losses
- Preprocess the BraTS2020 data using the provided preprocessing script.
- Create instances of the
BrainTumorDataset
class for training and validation sets. - Initialize the model, optimizer, and loss functions.
- Run the training loop, calling
train_epoch
andvalidate
functions for each epoch.
This project is based on BraTS2020 dataset. Ensure you have the correct data structure and file paths before running the preprocessing and training scripts.