diff --git a/README.md b/README.md index e6da894c1..4ca796ec0 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,6 @@ export nnUNet_results="/bluemind/nnunet/trains/nnUNet_results" Use [generate_json](scripts/generate_json.ipynb) for this. 4. #### Use scripts for training. -There are several scripts written by me (Roma) for datgaset [preprocessing](scripts/preprocess_data.sh), [training](scripts/train.sh), [finetuning](scripts/finetune.sh) and [predicting](scripts/predict.py). +There are several scripts written by me (Roma) for datgaset [preprocessing](scripts/preprocess.sh), [training](scripts/train.sh), [finetuning](scripts/finetune.sh). ### READ NNUUNET [README](readme.md) FOR MORE INFORMATION diff --git a/configs/mosaic_planner.json b/configs/mosaic_planner.json index 175520b7e..633f946b0 100644 --- a/configs/mosaic_planner.json +++ b/configs/mosaic_planner.json @@ -2,23 +2,26 @@ "3d_fullres_no_resampling": { "inherits_from": "3d_fullres", "resampling_fn_data": "no_resampling_data_or_seg_to_shape", + "resampling_fn_data_kwargs": {}, "resampling_fn_seg": "no_resampling_data_or_seg_to_shape", + "resampling_fn_seg_kwargs": {}, "resampling_fn_probabilities": "no_resampling_data_or_seg_to_shape", - "data_identifier": "3d_fullres_no_resampling" + "resampling_fn_probabilities_kwargs": {}, + "data_identifier": "nnUNetPlans_3d_fullres_NoRsmp" }, - "3d_fullres_mosaic_spacing_highres_NoRsmp": { + "3d_fullres_highres_NoRsmp": { "inherits_from": "3d_fullres_no_resampling", "spacing": [1.0, 1.0, 1.0], - "data_identifier": "3d_fullres_mosaic_spacing_highres_NoRsmp" + "data_identifier": "nnUNetPlans_3d_fullres_highres_NoRsmp" }, - "3d_fullres_mosaic_spacing_stdres_NoRsmp": { + "3d_fullres_stdres_NoRsmp": { "inherits_from": "3d_fullres_no_resampling", "spacing": [1.5, 1.5, 1.5], - "data_identifier": "3d_fullres_mosaic_spacing_stdres_NoRsmp" + "data_identifier": "nnUNetPlans_3d_fullres_stdres_NoRsmp" }, - "3d_fullres_mosaic_spacing_lowres_NoRsmp": { + "3d_fullres_lowres_NoRsmp": { "inherits_from": "3d_fullres_no_resampling", "spacing": [3.0, 3.0, 3.0], - "data_identifier": "3d_fullres_mosaic_spacing_lowres_NoRsmp" + "data_identifier": "nnUNetPlans_3d_fullres_lowres_NoRsmp" } } \ No newline at end of file diff --git a/nnunetv2/experiment_planning/experiment_planners/default_experiment_planner.py b/nnunetv2/experiment_planning/experiment_planners/default_experiment_planner.py index 566e99983..b8a71883b 100644 --- a/nnunetv2/experiment_planning/experiment_planners/default_experiment_planner.py +++ b/nnunetv2/experiment_planning/experiment_planners/default_experiment_planner.py @@ -544,19 +544,19 @@ def plan_experiment(self): plans['configurations']['3d_fullres_no_resampling'] = mosaic_planner['3d_fullres_no_resampling'] - plans['configurations']['3d_fullres_mosaic_spacing_highres_NoRsmp'] = mosaic_planner['3d_fullres_mosaic_spacing_highres_NoRsmp'] + plans['configurations']['3d_fullres_highres_NoRsmp'] = mosaic_planner['3d_fullres_highres_NoRsmp'] print('3D fullres Mosaic HighRes spacing No Resampling U-Net configuration:') - print(plans['configurations']['3d_fullres_mosaic_spacing_highres_NoRsmp']) + print(plans['configurations']['3d_fullres_highres_NoRsmp']) print() - plans['configurations']['3d_fullres_mosaic_spacing_stdres_NoRsmp'] = mosaic_planner['3d_fullres_mosaic_spacing_stdres_NoRsmp'] + plans['configurations']['3d_fullres_stdres_NoRsmp'] = mosaic_planner['3d_fullres_stdres_NoRsmp'] print('3D fullres Mosaic StdRes spacing No Resampling U-Net configuration:') - print(plans['configurations']['3d_fullres_mosaic_spacing_stdres_NoRsmp']) + print(plans['configurations']['3d_fullres_stdres_NoRsmp']) print() - plans['configurations']['3d_fullres_mosaic_spacing_lowres_NoRsmp'] = mosaic_planner['3d_fullres_mosaic_spacing_lowres_NoRsmp'] + plans['configurations']['3d_fullres_lowres_NoRsmp'] = mosaic_planner['3d_fullres_lowres_NoRsmp'] print('3D fullres Mosaic LowRes spacing No Resampling U-Net configuration:') - print(plans['configurations']['3d_fullres_mosaic_spacing_lowres_NoRsmp']) + print(plans['configurations']['3d_fullres_lowres_NoRsmp']) print() self.plans = plans diff --git a/nnunetv2/experiment_planning/experiment_planners/residual_unets/residual_encoder_unet_planners.py b/nnunetv2/experiment_planning/experiment_planners/residual_unets/residual_encoder_unet_planners.py index 413a305a8..012950b82 100644 --- a/nnunetv2/experiment_planning/experiment_planners/residual_unets/residual_encoder_unet_planners.py +++ b/nnunetv2/experiment_planning/experiment_planners/residual_unets/residual_encoder_unet_planners.py @@ -207,20 +207,12 @@ def _keygen(patch_size, strides): 'spacing': spacing, 'normalization_schemes': normalization_schemes, 'use_mask_for_norm': mask_is_used_for_norm, - #### MOSAIC CHAGES #### - # 'resampling_fn_data': resampling_data.__name__, - # 'resampling_fn_seg': resampling_seg.__name__, - # 'resampling_fn_data_kwargs': resampling_data_kwargs, - # 'resampling_fn_seg_kwargs': resampling_seg_kwargs, - # 'resampling_fn_probabilities': resampling_softmax.__name__, - # 'resampling_fn_probabilities_kwargs': resampling_softmax_kwargs, - #### MOSAIC CHAGES #### - 'resampling_fn_data': 'no_resampling_data_or_seg_to_shape', - 'resampling_fn_seg': 'no_resampling_data_or_seg_to_shape', - 'resampling_fn_data_kwargs': {}, - 'resampling_fn_seg_kwargs': {}, - 'resampling_fn_probabilities': 'no_resampling_data_or_seg_to_shape', - 'resampling_fn_probabilities_kwargs': {}, + 'resampling_fn_data': resampling_data.__name__, + 'resampling_fn_seg': resampling_seg.__name__, + 'resampling_fn_data_kwargs': resampling_data_kwargs, + 'resampling_fn_seg_kwargs': resampling_seg_kwargs, + 'resampling_fn_probabilities': resampling_softmax.__name__, + 'resampling_fn_probabilities_kwargs': resampling_softmax_kwargs, 'architecture': architecture_kwargs } return plan diff --git a/scripts/preprocess.sh b/scripts/preprocess.sh index 6af77a37f..396d5cc8a 100644 --- a/scripts/preprocess.sh +++ b/scripts/preprocess.sh @@ -3,34 +3,38 @@ echo "Mosaic Preprocessor. Be sure you have a dataset.json file in the raw directory!" read -p "Enter dataset id: " id read -p "Enter resolution (low | std | high): " res +read -p "Enter configuration (press Enter to set automatically): " config read -p "Enter planner (press Enter to set automatically): " planner read -p "Enter GPU memory (press Enter to set automatically): " gpu_mem -read -p "Enter number of processes (1-20, press Enter to use default 4): " np +read -p "Enter number of processes (1-20, press Enter to use default 8): " np # Устанавливаем количество процессов по умолчанию, если не указано -[[ -z "$np" ]] && np=4 +[[ -z "$np" ]] && np=8 declare -a spacing -# Настройка разрешения, планировщика и автоматическое определение памяти +# Настройка разрешения, планировщика, автоматическое определение памяти и конфигурации флага case "$res" in low) echo -e "\nLow resolution selected. Setting spacing at 3.0 3.0 3.0" spacing=(3.0 3.0 3.0) [[ -z "$planner" ]] && planner="nnUNetPlannerResEncM" [[ -z "$gpu_mem" ]] && gpu_mem=12 + [[ -z "$config" ]] && config="3d_fullres_lowres_NoRsmp" ;; std) echo -e "\nStandard resolution selected. Setting spacing at 1.5 1.5 1.5" spacing=(1.5 1.5 1.5) [[ -z "$planner" ]] && planner="nnUNetPlannerResEncL" [[ -z "$gpu_mem" ]] && gpu_mem=24 + [[ -z "$config" ]] && config="3d_fullres_stdres_NoRsmp" ;; high) echo -e "\nHigh resolution selected. Setting spacing at 1.0 1.0 1.0" spacing=(1.0 1.0 1.0) [[ -z "$planner" ]] && planner="nnUNetPlannerResEncXL" [[ -z "$gpu_mem" ]] && gpu_mem=40 + [[ -z "$config" ]] && config="3d_fullres_highres_NoRsmp" ;; *) echo -e "\nInvalid resolution option." @@ -39,7 +43,7 @@ case "$res" in esac nnUNetv2_plan_and_preprocess -d "$id" \ - -c 3d_fullres \ + -c "$config" \ -pl "$planner" \ -overwrite_target_spacing "${spacing[@]}" \ -gpu_memory_target "$gpu_mem" \ diff --git a/scripts/train.sh b/scripts/train.sh index 912f58847..6d5d9c29b 100755 --- a/scripts/train.sh +++ b/scripts/train.sh @@ -2,14 +2,46 @@ echo "Train model from scratch. Be sure that you have already created the dataset.json file!" read -p "Enter dataset id: " id -read -p "Enter train config (Press enter to set default 3d_fullres): " conf -read -p "Enter plans identifier (Press enter to set nnUNetPlans): " p +echo "Select train config: +0 - 3d_fullres +1 - 3d_fullres_lowres_NoRsmp +2 - 3d_fullres_stdres_NoRsmp +3 - 3d_fullres_highres_NoRsmp" +read -p "Enter train config number (Press enter to set default 0 - 3d_fullres): " conf_num +echo "Select trainer: +0 - nnUNetTrainer +1 - nnUNetTrainerNoMirroring +2 - nnUNetTrainer_250epochs_NoMirroring +3 - nnUNetTrainer_500epochs_NoMirroring +4 - nnUNetTrainer_750epochs_NoMirroring +5 - nnUNetTrainer_2000epochs_NoMirroring +6 - nnUNetTrainer_4000epochs_NoMirroring +7 - nnUNetTrainer_8000epochs_NoMirroring" +read -p "Enter trainer number: " trainer_num read -p "Enter train fold ([0-4] or all usually): " fold -read -p "Enter trainer (nnUNetTrainer, nnUNetTrainerNoMirroring, nnUNetTrainer_Xepochs_NoMirroring etc.): " trainer # Устанавливаем значение по умолчанию для конфигурации и плана, если они не указаны -[[ -z "$conf" ]] && conf="3d_fullres" -[[ -z "$p" ]] && p="nnUNetPlans" +case "$conf_num" in + 0) conf="3d_fullres" ;; + 1) conf="3d_fullres_lowres_NoRsmp" ;; + 2) conf="3d_fullres_stdres_NoRsmp" ;; + 3) conf="3d_fullres_highres_NoRsmp" ;; + *) conf="3d_fullres" ;; +esac + +plans="nnUNetPlans" + +case "$trainer_num" in + 0) trainer="nnUNetTrainer" ;; + 1) trainer="nnUNetTrainerNoMirroring" ;; + 2) trainer="nnUNetTrainer_250epochs_NoMirroring" ;; + 3) trainer="nnUNetTrainer_500epochs_NoMirroring" ;; + 4) trainer="nnUNetTrainer_750epochs_NoMirroring" ;; + 5) trainer="nnUNetTrainer_2000epochs_NoMirroring" ;; + 6) trainer="nnUNetTrainer_4000epochs_NoMirroring" ;; + 7) trainer="nnUNetTrainer_8000epochs_NoMirroring" ;; + *) echo "Error: Invalid trainer number."; exit 1 ;; +esac # Проверяем, указаны ли fold и trainer, и выводим ошибку в противном случае if [[ -z "$fold" ]]; then @@ -17,10 +49,5 @@ if [[ -z "$fold" ]]; then exit 1 fi -if [[ -z "$trainer" ]]; then - echo "Error: Trainer is required." - exit 1 -fi - echo "Launching the training process..." -nnUNetv2_train "$id" "$conf" "$fold" -p "$p" -tr "$trainer" \ No newline at end of file +nnUNetv2_train "$id" "$conf" "$fold" -p "$plans" -tr "$trainer" \ No newline at end of file