-
Notifications
You must be signed in to change notification settings - Fork 19
BAMF MR Brain tumor segmentation #93
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
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 15 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 hidden or 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,115 @@ | ||
general: | ||
data_base_dir: /app/data | ||
version: 1.0 | ||
description: Default configuration for Bamf NNUnet Brain tumor segmentation on MR scans (dicom to dicom) | ||
|
||
segdb: | ||
triplets: | ||
T_EDEMA_MABNORMALITY: | ||
code: 79654002 | ||
meaning: Edema | ||
scheme_designator: SCT | ||
T_NECROSIS_MABNORMALITY: | ||
code: 6574001 | ||
meaning: Necrosis | ||
scheme_designator: SCT | ||
T_ENHANCING_MABNORMALITY: | ||
code: C113842 | ||
meaning: Enhancing Lesion | ||
scheme_designator: NCIt | ||
segments: | ||
EDEMA: | ||
name: Edema | ||
category: C_MORPHOLOGICALLY_ABNORMAL_STRUCTURE | ||
type: T_EDEMA_MABNORMALITY | ||
color: [140, 224, 228] | ||
NECROSIS: | ||
name: Necrosis | ||
category: C_MORPHOLOGICALLY_ABNORMAL_STRUCTURE | ||
type: T_EDEMA_MABNORMALITY | ||
color: [216, 191, 216] | ||
ENHANCING: | ||
name: Enhancing Lesion | ||
category: C_MORPHOLOGICALLY_ABNORMAL_STRUCTURE | ||
type: T_ENHANCING_MABNORMALITY | ||
color: [128, 174, 128] | ||
LennyN95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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/$type@dicom:mod=mr | ||
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 hidden or 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"] |
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.
Uh oh!
There was an error while loading. Please reload this page.