diff --git a/NiChart_DLMUSE/__main__.py b/NiChart_DLMUSE/__main__.py index f340707..a070ebc 100644 --- a/NiChart_DLMUSE/__main__.py +++ b/NiChart_DLMUSE/__main__.py @@ -124,26 +124,20 @@ def main() -> None: no_threads = args.cores # for now subfolders = split_data(in_data, no_threads) - threads = [] - for i in range(len(subfolders)): + ##threads = [] + ##for i in range(len(subfolders)): + ## curr_out_dir = out_dir + f"split_{i}" + ## curr_thread = threading.Thread( + ## target=run_pipeline, args=(subfolders[i], curr_out_dir, device) + ## ) + ## curr_thread.start() + ## threads.append(curr_thread) + + ##for t in threads: + ## t.join() - if out_dir[len(out_dir) - 1] != '/': - # This is because sometimes users don't enter the dir - # like this: "output/" but like this "output" - out_dir += '/' - - curr_out_dir = out_dir + f"split_{i}" - curr_thread = threading.Thread( - target=run_pipeline, args=(subfolders[i], curr_out_dir, device) - ) - curr_thread.start() - threads.append(curr_thread) - - for t in threads: - t.join() - - remove_subfolders(in_data) merge_output_data(out_dir) + remove_subfolders(in_data) if __name__ == "__main__": main() diff --git a/NiChart_DLMUSE/utils.py b/NiChart_DLMUSE/utils.py index 5511369..100a543 100644 --- a/NiChart_DLMUSE/utils.py +++ b/NiChart_DLMUSE/utils.py @@ -169,7 +169,7 @@ def split_data(in_dir: str, N: int) -> list: def remove_subfolders(in_dir: str) -> None: - os.system(f"rm -r {in_dir}/split_*") + os.system(f"rm -r {in_dir}split_*") def merge_output_data(in_dir: str) -> None: os.system(f"mkdir {in_dir}results") @@ -181,14 +181,13 @@ def merge_output_data(in_dir: str) -> None: os.system(f"mkdir {in_dir}results/s6_combined") for dir in os.listdir(in_dir): - os.system(f"mv {in_dir}{dir}/s1_reorient_lps/* {in_dir}results/s1_reorient_lps/") - os.system(f"mv {in_dir}{dir}/s2_dlicv/* {in_dir}results/s2_dlicv/") - os.system(f"mv {in_dir}{dir}/s3_masked/* {in_dir}results/s3_masked/") - os.system(f"mv {in_dir}{dir}/s4_dlmuse/* {in_dir}results/s4_dlmuse/") - os.system(f"mv {in_dir}{dir}/s5_relabeled/* {in_dir}results/s5_relabeled/") - os.system(f"mv {in_dir}{dir}/s6_combined/* {in_dir}results/s6_combined/") - - os.system(f"mv {in_dir}*.nii.gz {in_dir}results/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s1_reorient_lps/* {in_dir}results/s1_reorient_lps/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s2_dlicv/* {in_dir}results/s2_dlicv/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s3_masked/* {in_dir}results/s3_masked/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s4_dlmuse/* {in_dir}results/s4_dlmuse/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s5_relabeled/* {in_dir}results/s5_relabeled/") + os.system(f"mv {in_dir}{dir}/temp_working_dir/s6_combined/* {in_dir}results/s6_combined/") + os.system(f"mv {in_dir}*.nii.gz {in_dir}results/") for dir in os.listdir(in_dir): os.system(f"rm -r {dir}") diff --git a/output/split_0/temp_working_dir/s2_dlicv/dataset.json b/output/results/s2_dlicv/dataset.json similarity index 100% rename from output/split_0/temp_working_dir/s2_dlicv/dataset.json rename to output/results/s2_dlicv/dataset.json diff --git a/output/split_0/temp_working_dir/s2_dlicv/plans.json b/output/results/s2_dlicv/plans.json similarity index 100% rename from output/split_0/temp_working_dir/s2_dlicv/plans.json rename to output/results/s2_dlicv/plans.json diff --git a/output/split_0/temp_working_dir/s2_dlicv/predict_from_raw_data_args.json b/output/results/s2_dlicv/predict_from_raw_data_args.json similarity index 100% rename from output/split_0/temp_working_dir/s2_dlicv/predict_from_raw_data_args.json rename to output/results/s2_dlicv/predict_from_raw_data_args.json diff --git a/output/split_2/temp_working_dir/s2_dlicv/renamed_image/renaming.json b/output/results/s2_dlicv/renamed_image/renaming.json similarity index 100% rename from output/split_2/temp_working_dir/s2_dlicv/renamed_image/renaming.json rename to output/results/s2_dlicv/renamed_image/renaming.json diff --git a/output/split_2/temp_working_dir/s2_dlicv/dataset.json b/output/split_2/temp_working_dir/s2_dlicv/dataset.json deleted file mode 100644 index c39f8d0..0000000 --- a/output/split_2/temp_working_dir/s2_dlicv/dataset.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "channel_names": { - "0": "MRI" - }, - "file_ending": ".nii.gz", - "labels": { - "background": 0, - "class1": 1 - }, - "numTraining": 1806 -} \ No newline at end of file diff --git a/output/split_2/temp_working_dir/s2_dlicv/plans.json b/output/split_2/temp_working_dir/s2_dlicv/plans.json deleted file mode 100644 index 0849bf1..0000000 --- a/output/split_2/temp_working_dir/s2_dlicv/plans.json +++ /dev/null @@ -1,434 +0,0 @@ -{ - "dataset_name": "Dataset901_Task901_dlicv", - "plans_name": "nnUNetPlans", - "original_median_spacing_after_transp": [ - 1.0, - 1.0, - 1.0 - ], - "original_median_shape_after_transp": [ - 255, - 255, - 176 - ], - "image_reader_writer": "SimpleITKIO", - "transpose_forward": [ - 0, - 1, - 2 - ], - "transpose_backward": [ - 0, - 1, - 2 - ], - "configurations": { - "2d": { - "data_identifier": "nnUNetPlans_2d", - "preprocessor_name": "DefaultPreprocessor", - "batch_size": 66, - "patch_size": [ - 256, - 192 - ], - "median_image_size_in_voxels": [ - 240.0, - 179.0 - ], - "spacing": [ - 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, - 2 - ], - "n_conv_per_stage_decoder": [ - 2, - 2, - 2, - 2, - 2 - ], - "num_pool_per_axis": [ - 5, - 5 - ], - "pool_op_kernel_sizes": [ - [ - 1, - 1 - ], - [ - 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 - ] - ], - "unet_max_num_features": 512, - "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": true - }, - "3d_lowres": { - "data_identifier": "nnUNetPlans_3d_lowres", - "preprocessor_name": "DefaultPreprocessor", - "batch_size": 2, - "patch_size": [ - 160, - 128, - 112 - ], - "median_image_size_in_voxels": [ - 235, - 226, - 169 - ], - "spacing": [ - 1.0609, - 1.0609, - 1.0609 - ], - "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, - 2 - ], - "n_conv_per_stage_decoder": [ - 2, - 2, - 2, - 2, - 2 - ], - "num_pool_per_axis": [ - 5, - 5, - 4 - ], - "pool_op_kernel_sizes": [ - [ - 1, - 1, - 1 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 1 - ] - ], - "conv_kernel_sizes": [ - [ - 3, - 3, - 3 - ], - [ - 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, - "next_stage": "3d_cascade_fullres" - }, - "3d_fullres": { - "data_identifier": "nnUNetPlans_3d_fullres", - "preprocessor_name": "DefaultPreprocessor", - "batch_size": 2, - "patch_size": [ - 160, - 128, - 112 - ], - "median_image_size_in_voxels": [ - 249.0, - 240.0, - 179.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, - 2 - ], - "n_conv_per_stage_decoder": [ - 2, - 2, - 2, - 2, - 2 - ], - "num_pool_per_axis": [ - 5, - 5, - 4 - ], - "pool_op_kernel_sizes": [ - [ - 1, - 1, - 1 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 2 - ], - [ - 2, - 2, - 1 - ] - ], - "conv_kernel_sizes": [ - [ - 3, - 3, - 3 - ], - [ - 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": true - }, - "3d_cascade_fullres": { - "inherits_from": "3d_fullres", - "previous_stage": "3d_lowres" - } - }, - "experiment_planner_used": "ExperimentPlanner", - "label_manager": "LabelManager", - "foreground_intensity_properties_per_channel": { - "0": { - "max": 8952.697265625, - "mean": 528.2257080078125, - "median": 317.0, - "min": -24.0, - "percentile_00_5": 20.0, - "percentile_99_5": 3972.0, - "std": 636.9642333984375 - } - } -} \ No newline at end of file diff --git a/output/split_2/temp_working_dir/s2_dlicv/predict_from_raw_data_args.json b/output/split_2/temp_working_dir/s2_dlicv/predict_from_raw_data_args.json deleted file mode 100644 index 4ff49a6..0000000 --- a/output/split_2/temp_working_dir/s2_dlicv/predict_from_raw_data_args.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "folder_with_segs_from_prev_stage": null, - "list_of_lists_or_source_folder": "/Users/spirosmag/Documents/NiChart_DLMUSE/output/split_2/temp_working_dir/s2_dlicv/renamed_image", - "num_parts": 1, - "num_processes_preprocessing": 2, - "num_processes_segmentation_export": 2, - "output_folder_or_list_of_truncated_output_files": "/Users/spirosmag/Documents/NiChart_DLMUSE/output/split_2/temp_working_dir/s2_dlicv", - "overwrite": true, - "part_id": 0, - "save_probabilities": false -} \ No newline at end of file