-
Notifications
You must be signed in to change notification settings - Fork 0
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
Train model with nnUnet or MONAI #75
Train model with nnUnet or MONAI #75
Comments
Hi @jcohenadad DescriptionMS lesion segmentation in 3T MP2RAGE images (UNI contrast) from Basel and Marseille using nnUnet. MP2RAGE dataset description (N=221)
CV in 5 folds keeping the heterogeneity of centers Data Preprocessing PipelineFor cropping I have added (24 + 5) x 2 pixels around SC mask (Fig. 1). Preprocessing pipeline# SC segmentation
sct_deepseg_sc -i UNI_image.nii.gz -o seg.nii.gz -c t1
# Dilate SC mask (5 pixels) in XYZ axis
sct_maths -i seg.nii.gz -dilate 5 -shape ball -o seg_dil5.nii.gz
# Dilate SC_dilated (24 pixels) in XY plane
sct_maths -i seg_dil5.nii.gz -dilate 24 -dim 2 -shape disk -o seg_dil24.nii.gz
# Crop UNI_image and Lesion masks at SC_dilated_24 mask size
sct_crop_image -i UNI_image.nii.gz -m seg_dil24.nii.gz -o UNIT1-crop.nii.gz
sct_crop_image -i UNIT1_lesion-manual.nii.gz" -m seg_dil24.nii.gz -o UNIT1-crop_lesion-manual.nii.gz Fig. 1: Marseille UNI image with seg_dil24 mask This way more pixels are stored in the XY plane so that after 5 downsampling more context information is stored, (p. 25 nnUnet paper ). Experiment planningAfter applying nnUNetPlans.json file
In the Based on this information, our 3D-Unet would look like this: Fig. 2 Trainings are currently running! |
Train 3D nnUnetFollowing the philosophy previously described, a 3D nnUnet network was trained, Preprocessing pipelinesubjects_basel =( sub-P001 sub-P002 sub-P003 sub-P004 ...)
subjects_marseille =( sub-MRS00 sub-MRS01 sub-MRS02 sub-MRS03 ...)
bids_file="basel-mrs-mp2rage"
bids_basel_input="basel-mp2rage"
bids_marseille_input="marseille-3T--mp2rage"
for subject in "${subjects_basel [@]}"
do
# Set orient image and lesions mask to RPI
sct_image -i ../$bids_basel_input/$subject/anat/$subject"_UNIT1.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1.nii.gz"
sct_image -i ../$bids_basel_input/derivatives/labels/$subject/anat/$subject"_UNIT1_lesion-manualNeuroPoly.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1_lesion.nii.gz"
sct_image -i ../$bids_basel_input/derivatives/labels/$subject/anat/$subject"_UNIT1_label-SC_seg.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz"
# Cropping with dilation (around the SC with 30 pixels in axial plane and 5 pixels in Z)
sct_crop_image -i tmp/$subject"_ses-M0_UNIT1.nii.gz" -m tmp/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz" -o $bids_file/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1.nii.gz" -dilate 30x30x5
sct_crop_image -i tmp/$subject"_ses-M0_UNIT1_lesion.nii.gz" -m tmp/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz" -o $bids_file/derivatives/labels/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1_label-lesion_rater2.nii.gz" -dilate 30x30x5
for subject in "${subjects_marseille [@]}"
do
# Set orient image and lesions mask to RPI M0 and M24
sct_image -i ../$bids_marseille_input/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1.nii.gz"
sct_image -i ../$bids_marseille_input/derivatives/labels/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1_label-lesion_rater2.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1_lesion.nii.gz"
sct_image -i ../$bids_marseille_input/derivatives/labels/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz" -setorient RPI -o tmp/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz"
# Cropping with dilation (around the SC with 30 pixels in axial plane and 5 pixels in Z) M0 and M24
sct_crop_image -i tmp/$subject"_ses-M0_UNIT1.nii.gz" -m tmp/$subject"_ses-M0_UNIT1_sc-all.nii.gz" -o $bids_file/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1.nii.gz" -dilate 30x30x5
sct_crop_image -i tmp/$subject"_ses-M0_UNIT1_lesion.nii.gz" -m tmp/$subject"_ses-M0_UNIT1_sc-all.nii.gz" -o $bids_file/derivatives/labels/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1_label-lesion_rater2.nii.gz" -dilate 30x30x5
done
Table 1 : Dataset Marseille - Basel for nnUnet model
Testing dataset from marseille are 3 subjects with M0 and M24 (so different subjects in Training and Testing ) nnUNetTrainer__nnUNetPlans__3d_fullres/plans.json "3d_fullres": {
"data_identifier": "nnUNetPlans_3d_fullres",
"preprocessor_name": "DefaultPreprocessor",
"batch_size": 7,
"patch_size": [
112,
80,
80
],
"median_image_size_in_voxels": [
99.0,
77.0,
75.0
],
"spacing": [
1.0,
1.0,
1.0
],
"normalization_schemes": [
"ZScoreNormalization"
],
"use_mask_for_norm": [
false
],
"UNet_class_name": "PlainConvUNet",
"UNet_base_num_features": 32,
"n_conv_per_stage_encoder": [
2,
2,
2,
2,
2
],
"n_conv_per_stage_decoder": [
2,
2,
2,
2
],
"num_pool_per_axis": [
4,
4,
4
],
"pool_op_kernel_sizes": [
[
1,
1,
1
],
[
2,
2,
2
],
[
2,
2,
2
],
[
2,
2,
2
],
[
2,
2,
2
]
],
"conv_kernel_sizes": [
[
3,
3,
3
],
[
3,
3,
3
],
[
3,
3,
3
],
[
3,
3,
3
],
[
3,
3,
3
]
],
"unet_max_num_features": 320,
"resampling_fn_data": "resample_data_or_seg_to_shape",
"resampling_fn_seg": "resample_data_or_seg_to_shape",
"resampling_fn_data_kwargs": {
"is_seg": false,
"order": 3,
"order_z": 0,
"force_separate_z": null
},
"resampling_fn_seg_kwargs": {
"is_seg": true,
"order": 1,
"order_z": 0,
"force_separate_z": null
},
"resampling_fn_probabilities": "resample_data_or_seg_to_shape",
"resampling_fn_probabilities_kwargs": {
"is_seg": false,
"order": 1,
"order_z": 0,
"force_separate_z": null
},
"batch_dice": false Models to segment lesions in MP2RAGE data
Preliminary results on testing dataset (Table 1)Preprocessing pipeline for `algo-1` testing#!/bin/bash
subjects=( sub-P001 sub-P002 sub-P003 ... )
for subject in "${subjects[@]}"
do
sct_maths -i ../../mrs_basel/basel-mrs-mp2rage/derivatives/labels/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1_label-SC_seg.nii.gz" -dilate 5 -shape ball -o $subject"_UNIT1_label-SC_seg_dil5.nii.gz"
sct_maths -i $subject"_UNIT1_label-SC_seg_dil5.nii.gz" -dilate 32 -dim 2 -shape disk -o $subject"_UNIT1_label-SC_seg_dil32.nii.gz"
sct_crop_image -i ../../mrs_basel/basel-mrs-mp2rage/$subject/ses-M0/anat/$subject"_ses-M0_UNIT1.nii.gz" -m $subject"_UNIT1_label-SC_seg_dil32.nii.gz" -o $subject"_UNIT1_crop.nii.gz"
# Run prediction
list_seed=(01 02 03 04 05)
for seed in ${list_seed[@]}; do
ivadomed_segment_image -i $subject"_UNIT1_crop.nii.gz" -m ../../ivadomed_env/model_r20230210/model_seg_lesion_mp2rage_r20230210_dil32_seed${seed}/model_seg_ms_lesion_mp2rage/ -s _pred${seed}
done
sct_image -i $subject"_UNIT1_crop"_pred*.nii.gz -concat t -o $subject"_UNIT1_crop_predMean.nii.gz"
sct_maths -i $subject"_UNIT1_crop_predMean.nii.gz" -mean t -o $subject"_UNIT1_crop_Mean.nii.gz"
sct_maths -i $subject"_UNIT1_crop_Mean.nii.gz" -bin 0.2 -o $subject"_UNIT1_lesion_bin.nii.gz"
done
Legend of QC masks
Testing in other MP2RAGE datasets:nih-ms-mp2rage (no GT)Legend of QC masks
marseille-7T-iso-mp2rage (no GT)
marseille-7T-aniso-mp2rage (no GT)
Next steps:
|
Single-class VS Multi-class model
Results
|
algo2 seems better to start off for creating the GT for:
|
Remove dependency from ivadomed and train model with nnUnet or MONAI.
The text was updated successfully, but these errors were encountered: