Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAMF MR Brain tumor segmentation #93

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6146429
MR Brain tumor segmentation
jithenece Jul 9, 2024
22636ff
add custom segdb entries
jithenece Jul 11, 2024
afcda3e
use gcc11.4 in synch to training code base
jithenece Jul 20, 2024
029fa7f
remove files
jithenece Jul 24, 2024
0bdc69f
change working dir
jithenece Jul 24, 2024
03679eb
add meta
jithenece Jul 30, 2024
2acda92
set order
jithenece Jul 30, 2024
c1b29fd
fix dockerfile
jithenece Jul 31, 2024
f11aeb0
MHub compliance rule fixes
jithenece Jul 31, 2024
75050b2
MHub compliance rule fixes
jithenece Jul 31, 2024
b927a85
Dockerfile replace copy with build
jithenece Aug 1, 2024
f158a7d
separate single processor into multiple modules
jithenece Aug 7, 2024
43a08df
format label name and value
jithenece Aug 7, 2024
ef4621f
fix review comments
jithenece Aug 21, 2024
be2e7a0
fix review comment
jithenece Aug 22, 2024
d382e5f
remove custom seg entries
jithenece Aug 23, 2024
1126c9d
fix code comments
jithenece Aug 23, 2024
57b1f56
fix meta comments
jithenece Aug 23, 2024
16196f7
add limitations
jithenece Aug 23, 2024
49bdb90
fix workflow
jithenece Aug 23, 2024
044d076
fix meta
jithenece Aug 23, 2024
5be31ea
update model name
jithenece Aug 26, 2024
996d543
update process flag
jithenece Aug 27, 2024
628022d
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece Aug 27, 2024
f40185f
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece Sep 9, 2024
8a4967d
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece Oct 1, 2024
489d518
update python dependencies
jithenece Oct 2, 2024
224131a
/test validation
jithenece Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions models/bamf_mr_brain_tumor/config/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
general:
data_base_dir: /app/data
version: 1.0
description: Default configuration for Bamf NNUnet Brain tumor segmentation on MR scans (dicom to dicom)

execute:
- FileStructureImporter
- NiftiConverter
- ReOrientationRunner
- BiasCorrectionRunner
- FLIRTRegistrationRunner
- SkullStripRunner
- StdRegistrationRunner
- NNUnetRunnerV2
- InverseStdRegistrationRunner
- InverseRegistrationRunner
- module: DsegConverter
target_dicom: dicom:mod=mr:type=t1
source_segs: nifti:mod=mr:type=t1:task=inverse
- module: DsegConverter
target_dicom: dicom:mod=mr:type=t1ce
source_segs: nifti:mod=mr:type=t1ce:task=inverse
- module: DsegConverter
target_dicom: dicom:mod=mr:type=t2
source_segs: nifti:mod=mr:type=t2:task=inverse
- module: DsegConverter
target_dicom: dicom:mod=mr:type=flair
source_segs: nifti:mod=mr:type=flair:task=inverse
- DataOrganizer

modules:
FileStructureImporter:
input_dir: 'input_data'
structures:
- $patientID@instance/t1@dicom:mod=mr:type=t1
- $patientID/t1ce@dicom:mod=mr:type=t1ce
- $patientID/t2@dicom:mod=mr:type=t2
- $patientID/flair@dicom:mod=mr:type=flair
import_id: patientID

NiftiConverter:
allow_multi_input: True
out_datas: nifti:mod=mr:task=conversion
engine: dcm2niix

ReOrientationRunner:
in_datas: nifti:mod=mr

BiasCorrectionRunner:
in_datas: nifti:mod=mr:task=reorientation

FLIRTRegistrationRunner:
in_datas: nifti:mod=mr:task=bias_corrected
reference_data: nifti:mod=mr:task=bias_corrected:type=t1ce

SkullStripRunner:
in_datas: nifti:mod=mr:task=registration

StdRegistrationRunner:
in_datas: nifti:mod=mr:task=skull_stripped

NNUnetRunnerV2:
in_t1_data: nifti:mod=mr:task=std_registration:type=t1
in_t1ce_data: nifti:mod=mr:task=std_registration:type=t1ce
in_t2_data: nifti:mod=mr:task=std_registration:type=t2
in_flair_data: nifti:mod=mr:task=std_registration:type=flair

InverseStdRegistrationRunner:
in_seg_data: nifti:mod=seg:model=nnunet:nnunet_dataset=Dataset002_BRATS19
in_mat_datas: txt:task=std_registration_transform_mat
in_registration_datas: nifti:mod=mr:task=registration

InverseRegistrationRunner:
in_seg_datas: nifti:mod=mr:task=std_inverse
in_mat_datas: txt:task=registration_transform_mat
in_registration_datas: nifti:mod=mr:task=bias_corrected

DsegConverter:
model_name: BAMF Brain Tumor AI Segmentation
skip_empty_slices: True

DataOrganizer:
targets:
- dicomseg:type=t1ce-->[i:patientID]/t1ce.seg.dcm
- dicomseg:type=t1-->[i:patientID]/t1.seg.dcm
- dicomseg:type=t2-->[i:patientID]/t2.seg.dcm
- dicomseg:type=flair-->[i:patientID]/flair.seg.dcm
78 changes: 78 additions & 0 deletions models/bamf_mr_brain_tumor/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
FROM mhubai/base:latest

ENV DEBIAN_FRONTEND "noninteractive"
ENV LANG "en_GB.UTF-8"

# 1. Install gcc-14 and build ants
RUN apt-get update && apt-get install -y cmake make ninja-build git bzip2 flex manpages-dev g++ wget unzip file
RUN wget https://github.com/gcc-mirror/gcc/archive/refs/tags/releases/gcc-11.4.0.zip \
&& unzip gcc-11.4.0.zip && cd gcc-releases-gcc-11.4.0 && ./contrib/download_prerequisites \
&& mkdir /app/gcc-build && cd /app/gcc-build \
&& ../gcc-releases-gcc-11.4.0/configure -v --target=x86_64-linux-gnu --prefix=/usr/local/gcc-11.4.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-11.4 \
&& make -j$(nproc) && make install-strip \
&& update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-11.4.0/bin/gcc-11.4 11 --slave /usr/bin/g++ g++ /usr/local/gcc-11.4.0/bin/g++-11.4 \
&& rm -rf /app/gcc-*

ENV PATH=/usr/local/gcc-11.4.0/bin:$PATH
ENV LD_LIBRARY_PATH="/usr/local/gcc-11.4.0/lib64:$LD_LIBRARY_PATH"

RUN git clone https://github.com/ANTsX/ANTs.git /usr/local/src/ants \
&& mkdir /app/build && cd /app/build && cmake -DBUILD_TESTING=ON \
-DRUN_LONG_TESTS=OFF \
-DRUN_SHORT_TESTS=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=/opt/ants \
/usr/local/src/ants \
&& cmake --build . --parallel \
&& cd /app/build/ANTS-build && cmake --build . --target test \
&& cmake --install . && rm -rf /app/build

# 2. Install mri_convert
ENV FREESURFER_HOME="/freesurfer"
RUN git clone https://github.com/freesurfer/freesurfer.git && cd freesurfer/mri_synthstrip \
git+https://github.com/freesurfer/surfa.git@0d83332351083b33c4da221e9d10a63a93ae7f52 \
&& mkdir -p $FREESURFER_HOME/models/ \
&& git remote add datasrc https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/repo/annex.git \
&& apt-get update -y && apt-get install -y git-annex \
&& git fetch datasrc && git-annex get . \
&& cp mri_synthstrip $FREESURFER_HOME \
&& cp synthstrip.*.pt $FREESURFER_HOME/models/

# 3. Install fsl
RUN wget https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/fslinstaller.py && \
python3 ./fslinstaller.py -V 6.0.7.11 -d /usr/local/fsl/ && rm fslinstaller.py

ENV PATH="/opt/ants/bin:$PATH:/$FREESURFER_HOME:/usr/local/fsl/bin" \
LD_LIBRARY_PATH="/opt/ants/lib:$LD_LIBRARY_PATH"

# 3. Install nnunet
# FIXME: set this environment variable as a shortcut to avoid nnunet crashing the build
# by pulling sklearn instead of scikit-learn
# N.B. this is a known issue:
# https://github.com/MIC-DKFZ/nnUNet/issues/1281
# https://github.com/MIC-DKFZ/nnUNet/pull/1209
ENV SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True

# 4. Install nnunet and surfa
RUN uv pip install torch==2.4.1 nnunetv2==2.4.1 surfa==0.6.1
RUN apt-get update && apt-get install -y bc

# Clone the main branch of MHubAI/models
ARG MHUB_MODELS_REPO
RUN buildutils/import_mhub_model.sh bamf_mr_brain_tumor ${MHUB_MODELS_REPO}

# Pull nnUNet model weights into the container
ENV WEIGHTS_DIR=/root/.nnunet/nnUNet_models/
RUN mkdir -p $WEIGHTS_DIR
ENV WEIGHTS_FN=Dataset002_BRATS19.zip
ENV WEIGHTS_URL=https://zenodo.org/records/11582627/files/$WEIGHTS_FN
RUN wget --directory-prefix ${WEIGHTS_DIR} ${WEIGHTS_URL}
RUN unzip ${WEIGHTS_DIR}${WEIGHTS_FN} -d ${WEIGHTS_DIR}
RUN rm ${WEIGHTS_DIR}${WEIGHTS_FN}

# specify nnunet specific environment variables
ENV WEIGHTS_FOLDER=$WEIGHTS_DIR

# Default run script
ENTRYPOINT ["mhub.run"]
CMD ["--config", "/app/models/bamf_mr_brain_tumor/config/default.yml"]
211 changes: 211 additions & 0 deletions models/bamf_mr_brain_tumor/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"id": "",
"name": "bamf_mr_brain_tumor",
"title": "BAMF MR Brain Tumor",
"summary": {
"description": "An nnU-Net based model to segment brain tumors using four MR modalities Fluid Attenuated Inversion Recovery (FLAIR), native (T1), post-contrast T1-weighted (T1Gd), and T2-weighted (T2)",
"inputs": [
{
"label": "Input Image",
"description": "native (T1) MRI scan of a patient.",
"format": "DICOM",
"modality": "MRI",
"bodypartexamined": "BRAIN",
"slicethickness": "1mm",
"non-contrast": true,
"contrast": false
},
{
"label": "Input Image",
"description": "post-contrast T1-weighted MRI scan of a patient.",
"format": "DICOM",
"modality": "MRI",
"bodypartexamined": "BRAIN",
"slicethickness": "1mm",
"non-contrast": false,
"contrast": true
},
{
"label": "Input Image",
"description": "T2-weighted MRI scan of a patient.",
"format": "DICOM",
"modality": "MRI",
"bodypartexamined": "BRAIN",
"slicethickness": "1mm",
"non-contrast": true,
"contrast": false
},
{
"label": "Input Image",
"description": "T2 Fluid Attenuated Inversion Recovery (T2-FLAIR) MRI scan of a patient.",
"format": "DICOM",
"modality": "MRI",
"bodypartexamined": "BRAIN",
"slicethickness": "1mm",
"non-contrast": true,
"contrast": false
}
],
"outputs": [
{
"label": "T1 Segmentation",
"type": "Segmentation",
"description": "Tumor Segmentation of T1 MRI scan",
"classes": [
"NECROSIS",
"EDEMA",
"ENHANCING_LESION"
]
},
{
"label": "T1ce Segmentation",
"type": "Segmentation",
"description": "Tumor Segmentation of T1ce MRI scan",
"classes": [
"NECROSIS",
"EDEMA",
"ENHANCING_LESION"
]
},
{
"label": "T2 Segmentation",
"type": "Segmentation",
"description": "Tumor Segmentation of T2 MRI scan",
"classes": [
"NECROSIS",
"EDEMA",
"ENHANCING_LESION"
]
},
{
"label": "FLAIR Segmentation",
"type": "Segmentation",
"description": "Tumor Segmentation of FLAIR MRI scan",
"classes": [
"NECROSIS",
"EDEMA",
"ENHANCING_LESION"
]
}
],
"model": {
"architecture": "U-net",
"training": "supervised",
"cmpapproach": "3D"
},
"data": {
"training": {
"vol_samples": 1251
},
"evaluation": {
"vol_samples": 45
},
"public": true,
"external": true
}
},
"details": {
"name": "AIMI MR Brain Tumor",
"version": "1.0.0",
"devteam": "BAMF Health",
"authors": [
"Soni, Rahul",
"McCrumb, Diana",
"Murugesan, Gowtham Krishnan",
"Van Oss, Jeff",
"Jithendra Kumar"
],
"type": "nnU-Net (U-Net structure, optimized by data-driven heuristics)",
"date": {
"code": "30.08.2024",
"weights": "11.06.2024",
"pub": "30.08.2024"
},
"cite": "Gowtham Krishnan Murugesan, Diana McCrumb, Rahul Soni, Jithendra Kumar, Leonard Nuernberg, Linmin Pei, Ulrike Wagner, Sutton Granger, Andrey Y. Fedorov, Stephen Moore, Jeff Van Oss. AI generated annotations for Breast, Brain, Liver, Lungs and Prostate cancer collections in National Cancer Institute Imaging Data Commons. arXiv:2409.20342 (2024).",
"license": {
"code": "MIT",
"weights": "CC BY-NC 4.0"
},
"publications": [
{
"title": "AI generated annotations for Breast, Brain, Liver, Lungs and Prostate cancer collections in National Cancer Institute Imaging Data Commons",
"uri": "https://arxiv.org/abs/2409.20342"
}
],
"github": "https://github.com/bamf-health/aimi-brain-mr"
},
"info": {
"use": {
"title": "Intended Use",
"text": "To perform tumor segmentation in Brain MRI scans, you need four MRI modalities—T1-weighted, T1 with contrast enhancement (T1ce), T2-weighted, and FLAIR—each providing critical information about brain anatomy and tumor characteristics. The data should be organized in separated directories per instance (e.g., named by a unique sample or patient identifier) with one subfolder for each of the four input modalities, containing the respective DICOM files (namely 't1', 't1ce', 't2', and 'flair'). The model processes these inputs to produce three segmentation maps for necrosis, edema, and enhancing tumor regions. These outputs are vital for clinical applications like treatment planning, monitoring tumor progression, and prognosis, as well as for research projects focused on developing new algorithms, identifying imaging biomarkers, and integrating automated segmentation into clinical workflows"
},
"analyses": {
"title": "Quantitative Analyses",
"text": "The model's performance was assessed using the Dice Coefficient and Normalized Surface Distance (NSD) with tolerance 7mm. The analysis is published here [2]",
"tables": [
{
"label": "Label-wise metrics Dice score between AI derived and manually corrected annotations",
"entries": {
"Whole Tumor": "0.98±0.07",
"Enhancing Tumor": "0.95±0.13",
"Non enhancing Tumor": "0.97±0.08"
}
},
{
"label": "Label-wise metrics 95% Hausdorff Distance between AI derived and manually corrected annotations",
"entries": {
"Whole Tumor": "6.88±0.34",
"Enhancing Tumor": "6.57±0.24",
"Non enhancing Tumor": "0.42±1.05"
}
},
{
"label": "Label-wise metrics NSD score between AI derived and manually corrected annotations",
"entries": {
"Whole Tumor": "0.98±0.04",
"Enhancing Tumor": "0.99±0.03",
"Non enhancing Tumor": "0.97±0.09"
}
}
],
"references": [
{
"label": "UPENN-GBM",
"uri": "https://www.cancerimagingarchive.net/collection/upenn-gbm/"
},
{
"label": "AI generated annotations for Breast, Brain, Liver, Lungs and Prostate cancer collections in National Cancer Institute Imaging Data Commons",
"uri": "https://arxiv.org/abs/2409.20342"
}
]
},
"evaluation": {
"title": "Evaluation Data",
"text": "The model was used to segment 541 cases from the IDC [1] collection UPENN-GBM [1]. Approximately 10% of these annotations, 45 cases were randomly selected to be reviewed and corrected by a board-certified radiologist. Quality metrics such as Dice coefficient, normalized surface distance (NSD), and detection accuracy were reported",
"references": [
{
"label": "Imaging Data Collections (IDC)",
"uri": "https://datacommons.cancer.gov/repository/imaging-data-commons"
},
{
"label": "UPENN-GBM",
"uri": "https://www.cancerimagingarchive.net/collection/upenn-gbm/"
}
]
},
"training": {
"title": "Training Data",
"text": "The training dataset used from the BraTS21 challenge consists of 1,251 brain mpMRI scans along with segmentation annotations of tumorous regions. The 3D volumes were skull-stripped and resampled to 1 mm isotropic resolution, with dimensions of (240, 240, 155) voxels. For each example, four modalities were given: Fluid Attenuated Inversion Recovery (FLAIR), native (T1), post-contrast T1-weighted (T1Gd), and T2-weighted (T2). Annotations consisted of four classes: 1 for necrotic tumor core (NCR), 2 for peritumoral edematous tissue (ED), 4 for enhancing tumor (ET), and 0 for background (voxels that are not part of the tumor).",
"references": [
{
"label": "Brain Tumor Segmentation (BraTS)",
"uri": "http://braintumorsegmentation.org"
}
]
},
"limitations": {
"title": "Limitations",
"text": "The model has been trained and tested on scans acquired during clinical care of patients, so it might not be suited for a healthy population. The generalization capabilities of the model on a range of ages, genders, and ethnicities are unknown."
}
}
}
3 changes: 3 additions & 0 deletions models/bamf_mr_brain_tumor/mhub.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

[model.deployment]
test = "https://zenodo.org/records/13880663/files/bamf_mr_brain_tumor.test.zip?download=1"
Binary file not shown.
Loading
Loading