This repository contains the implementation of a deep learning-based brain tumor segmentation model using a hybrid FPN-3D U-Net architecture. This project addresses the critical need for automated, accurate, and efficient segmentation of brain tumors in MRI scans, aiding medical professionals in diagnosis and treatment planning.
- Project Overview
- Dataset
- Preprocessing Pipeline
- Model Architecture
- Training and Evaluation
- Results and Analysis
- How to Use
- References
This project aims to develop a 3D segmentation model that can accurately segment brain tumors into four classes:
- Necrotic core
- Peritumoral edema
- Enhancing tumor
- Background
Manual segmentation of brain tumors is time-consuming, prone to variability, and dependent on expert radiologists. This project leverages deep learning to:
- Automate segmentation tasks.
- Provide consistent and reliable results.
- Improve diagnostic workflows, especially in resource-limited settings.
- Utilizes BraTS21 Dataset, which includes four MRI modalities: FLAIR, T1, T1Gd, and T2.
- Integrates a Feature Pyramid Network (FPN) with a 3D U-Net for enhanced multi-scale feature extraction.
- Employs a custom Dice-Cross Entropy Loss function to handle class imbalance and improve segmentation accuracy.
- Comprehensive preprocessing pipeline to standardize and augment data.
The BraTS21 Dataset is a benchmark dataset for brain tumor segmentation. It contains 3D MRI scans with expert-annotated segmentation labels.
- FLAIR: Highlights abnormalities such as edema.
- T1-weighted: Provides anatomical details of brain structures.
- Post-contrast T1-weighted (T1Gd): Enhances active tumor regions.
- T2-weighted: Emphasizes fluid-rich areas and complements FLAIR.
- 1,251 MRI scans.
- Four modalities per scan.
- Each scan is resampled to a uniform voxel size of 1 mm isotropic.
- Segmentation annotations include four classes.
Visualization of MRI Modalities:

A robust preprocessing pipeline was developed to standardize and prepare the dataset for training:
-
Skull-Stripping:
- Removes non-brain tissues, focusing solely on the brain.
-
Resampling:
- Resamples scans to a uniform voxel resolution of 1 mm isotropic.
-
Cropping to Foreground:
- Reduces unnecessary background regions by cropping around the brain.
-
Intensity Normalization:
- Standardizes voxel intensity to have zero mean and unit variance.
-
Augmentation:
- Includes random flips, rotations, and gamma adjustments to enhance diversity.
-
Resizing:
- Rescales scans to a fixed size of 128 x 128 x 128 voxels.
Example of a Preprocessed Image:

The proposed model combines the 3D U-Net with a Feature Pyramid Network (FPN) to leverage multi-scale feature extraction.
-
Encoder:
- Extracts hierarchical features using convolutional blocks and downsampling.
-
FPN Layers:
- Integrates multi-scale features for better context and detail.
-
Decoder:
- Reconstructs high-resolution segmentation maps using skip connections and upsampling layers.
-
Custom Loss Function:
- Combines Dice Loss and Cross-Entropy Loss to address imbalanced data.
- Batch Size: 1
- Epochs: 10
- Learning Rate: 0.0003
- Optimizer: Adam
The combined loss function:
- Dice Loss: Measures overlap between predicted and true segmentation.
- Cross-Entropy Loss: Penalizes incorrect class predictions.
- Dice Similarity Coefficient (DSC): Evaluates segmentation accuracy.
git clone https://github.com/your-username/brain-tumor-segmentation.git
cd brain-tumor-segmentationpip install -r requirements.txtpython preprocess.pypython main.py --mode trainpython main.py --mode test --weights final_model.pth- Havaei, M., et al., "Brain Tumor Segmentation with Deep Neural Networks," Medical Image Analysis, 2017.
- Bakas, S., et al., "Segmentation Labels and Radiomic Features for TCGA-GBM Collection," The Cancer Imaging Archive, 2017.
- Çiçek, Ö., et al., "3D U-Net: Learning Dense Volumetric Segmentation from Sparse Annotation," MICCAI 2016.
- Brain tumor image segmentation based on improved FPN,Haitao Sun, Shuai Yang, Lijuan Chen, Pingyan Liao, Xiangping Liu, Ying Liu & Ning Wang BMC Medical Imaging
