Junmo Kwon1, Sang Won Seo2, Hwan-ho Cho3, Hyunjin Park1
1Department of Electrical and Computer Engineering, Sungkyunkwan University, Suwon 16419, South Korea
2Department of Neurology, Samsung Medical Center, Sungkyunkwan University School of Medicine, Seoul 06351, South Korea
3Department of Electronics Engineering, Incheon National University, Incheon 22012, South Korea
Follow the installation guide to install nnUNet-v2.
Download the two files to setup our CMB preprocessing framework:
- Download
local_minima_preprocessor.pytonnunetv2/preprocessing/preprocessors/local_minima_preprocessor.py. - Download
local_minima_planners.pytonnunetv2/experiment_planning/experiment_planners/residual_unets/local_minima_planners.py.
The CMB training dataset requires co-registered T1- and T2*-weighted MRI scans for every subject. Your dataset.json should follow this format:
{
"channel_names": {
"0": "T2S",
"1": "T1"
},
"file_ending": ".nii.gz",
"labels": {
"CMB": 1,
"background": 0
},
"numTraining": 0,
"overwrite_image_reader_writer": "SimpleITKIO"
}
where numTraining should match the size of your training dataset.
Please ensure the channel name of T2* MRI scan is set to T2S.
This is necessary for local_minima_preprocessor.py to process minimum filtering and local minima extraction.
local_minima_planners.py offers three input patch size:
LocalMinimaResEncL24for 24×448×384LocalMinimaResEncL16for 16×224×192LocalMinimaResEncL12for 12×112×96
Always start by running the default experiment planning on your dataset. Then, adjust the input patch size to your desired size.
import os
working_dir = 'path/to/working/directory'
os.environ['nnUNet_raw'] = os.path.join(working_dir, 'nnUNet_raw')
os.environ['nnUNet_preprocessed'] = os.path.join(working_dir, 'nnUNet_preprocessed')
os.environ['nnUNet_results'] = os.path.join(working_dir, 'nnUNet_results')
dataset_id = 1 # your dataset id
plan = 'LocalMinimaResEncL24'
preprocessor = 'LocalMinimaPreprocessor'
!nnUNetv2_plan_and_preprocess -c 3d_fullres -d "{dataset_id}" -pl "{plan}" -preprocessor_name "{preprocessor}" --verbose
dataset_id = 1 # your dataset id
plan = 'LocalMinimaResEncL24' # your plan name
for fold in (0, 1, 2, 3, 4):
!CUDA_VISIBLE_DEVICES=0 nnUNetv2_train "{dataset_id}" 3d_fullres "{fold}" -p "{plan}" --c
dataset_id = 1 # your dataset id
plan = 'LocalMinimaResEncL24' # your plan name
input_path = 'path/to/test/set'
output_path = 'path/to/output/path'
for fold in (0, 1, 2, 3, 4):
!CUDA_VISIBLE_DEVICES=0 nnUNetv2_predict -d "{dataset_id}" -c 3d_fullres -f "{fold}" -i "{input_path}" -o "{output_path}" -p "{plan}"
The current local_minima_preprocessor.py only supports binary CMB segmentation and should not be used for multi-class segmentation.
Attempting to use it for multi-class segmentation will trigger the following assertion error:
assert len(classes_or_regions) == 1, f"LocalMinimaPreprocessor currently supports only binary segmentation whereas the given data has {classes_or_regions} classes"
The tricky part is that classes_or_regions could be either class or region, where region denotes region-based training.
If you are absolutely certain that classes_or_regions always indicates classes, then you may try to adapt the local minima preprocessing as follows.
- Determine the class index that represents CMB (by reading the
dataset_json) - Apply the local minima preprocessing to the given CMB index
- Apply the conventional foreground sampling to all remaining class indices.
Part of the codes are referred from the following open-source projects: