-
Notifications
You must be signed in to change notification settings - Fork 18
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
jithenece
wants to merge
28
commits into
MHubAI:main
Choose a base branch
from
bamf-health:bamf_mr_brain_tumor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6146429
MR Brain tumor segmentation
jithenece 22636ff
add custom segdb entries
jithenece afcda3e
use gcc11.4 in synch to training code base
jithenece 029fa7f
remove files
jithenece 0bdc69f
change working dir
jithenece 03679eb
add meta
jithenece 2acda92
set order
jithenece c1b29fd
fix dockerfile
jithenece f11aeb0
MHub compliance rule fixes
jithenece 75050b2
MHub compliance rule fixes
jithenece b927a85
Dockerfile replace copy with build
jithenece f158a7d
separate single processor into multiple modules
jithenece 43a08df
format label name and value
jithenece ef4621f
fix review comments
jithenece be2e7a0
fix review comment
jithenece d382e5f
remove custom seg entries
jithenece 1126c9d
fix code comments
jithenece 57b1f56
fix meta comments
jithenece 16196f7
add limitations
jithenece 49bdb90
fix workflow
jithenece 044d076
fix meta
jithenece 5be31ea
update model name
jithenece 996d543
update process flag
jithenece 628022d
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece f40185f
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece 8a4967d
Merge branch 'MHubAI:main' into bamf_mr_brain_tumor
jithenece 489d518
update python dependencies
jithenece 224131a
/test validation
jithenece File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/$type@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 NNUnet Brain 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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 pip3 install --no-cache-dir torch surfa==0.6 | ||
RUN apt-get update && apt-get install -y python3.9 python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
RUN python3.9 -m pip install nnunetv2==2.4.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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
{ | ||
"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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The convention is all-uppercase, e.g., |
||
"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": "3mm", | ||
"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" | ||
], | ||
"type": "nnU-Net (U-Net structure, optimized by data-driven heuristics)", | ||
"date": { | ||
"code": "17.10.2023", | ||
"weights": "28.08.2023", | ||
"pub": "23.10.2023" | ||
}, | ||
"cite": "Murugesan, Gowtham Krishnan, Diana McCrumb, Mariam Aboian, Tej Verma, Rahul Soni, Fatima Memon, and Jeff Van Oss. The AIMI Initiative: AI-Generated Annotations for Imaging Data Commons Collections. arXiv preprint arXiv:2310.14897 (2023).", | ||
"license": { | ||
"code": "MIT", | ||
"weights": "CC BY-NC 4.0" | ||
}, | ||
"publications": [ | ||
{ | ||
"title": "The AIMI Initiative: AI-Generated Annotations in IDC Collections", | ||
"uri": "https://arxiv.org/abs/2310.14897" | ||
} | ||
], | ||
"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 an input directory with subfolders for each modality, containing the respective DICOM files. 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" | ||
LennyN95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"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": "The AIMI Initiative: AI-Generated Annotations for Imaging Data Commons Collections", | ||
"uri": "https://arxiv.org/abs/2310.14897" | ||
} | ||
] | ||
}, | ||
"evaluation": { | ||
"title": "Evaluation Data", | ||
"text": "The model was used to 541 segment 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" | ||
} | ||
] | ||
} | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you use a
$type
meta variable in the 3rd structure directive. I assume this is not on purpose. Instead, either use a specific declaration:This is equivalent to the use of a variable as in the example below, because the
$type
variable will read the folder name and add it to thetype
meta key for all files imported under the folder. However, in this case it is not clear from the import directive how the folder structure needs to look like, hence the first option should be used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jithenece I see you already updated this to the latter example. However, for the transparency with we should stick with the first, more verbose variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explains. I have reverted this to earlier verbose variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jithenece Can you check if you pushed this already, I still see the simplified version in the most recent commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have pushed it now. please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still a
$type
variable (instead oft2
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed it. I have updated now.