Skip to content

Commit f4103c5

Browse files
authored
Update test_nnunetv2runner (#7483)
Fixes #7013 #7478 ### Description replace `predict_from_raw_data` with `nnUNetPredictor` in test_nnunetv2runner ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <[email protected]>
1 parent 1b93988 commit f4103c5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

monai/apps/nnunet/nnunetv2_runner.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class nnUNetV2Runner: # noqa: N801
3737
"""
3838
``nnUNetV2Runner`` provides an interface in MONAI to use `nnU-Net` V2 library to analyze, train, and evaluate
3939
neural networks for medical image segmentation tasks.
40+
A version of nnunetv2 higher than 2.2 is needed for this class.
4041
4142
``nnUNetV2Runner`` can be used in two ways:
4243
@@ -770,7 +771,7 @@ def find_best_configuration(
770771
def predict(
771772
self,
772773
list_of_lists_or_source_folder: str | list[list[str]],
773-
output_folder: str,
774+
output_folder: str | None | list[str],
774775
model_training_output_dir: str,
775776
use_folds: tuple[int, ...] | str | None = None,
776777
tile_step_size: float = 0.5,
@@ -824,28 +825,29 @@ def predict(
824825
"""
825826
os.environ["CUDA_VISIBLE_DEVICES"] = f"{gpu_id}"
826827

827-
from nnunetv2.inference.predict_from_raw_data import predict_from_raw_data
828+
from nnunetv2.inference.predict_from_raw_data import nnUNetPredictor
828829

829830
n_processes_preprocessing = (
830831
self.default_num_processes if num_processes_preprocessing < 0 else num_processes_preprocessing
831832
)
832833
n_processes_segmentation_export = (
833834
self.default_num_processes if num_processes_segmentation_export < 0 else num_processes_segmentation_export
834835
)
835-
836-
predict_from_raw_data(
837-
list_of_lists_or_source_folder=list_of_lists_or_source_folder,
838-
output_folder=output_folder,
839-
model_training_output_dir=model_training_output_dir,
840-
use_folds=use_folds,
836+
predictor = nnUNetPredictor(
841837
tile_step_size=tile_step_size,
842838
use_gaussian=use_gaussian,
843839
use_mirroring=use_mirroring,
844-
perform_everything_on_gpu=perform_everything_on_gpu,
840+
perform_everything_on_device=perform_everything_on_gpu,
845841
verbose=verbose,
842+
)
843+
predictor.initialize_from_trained_model_folder(
844+
model_training_output_dir=model_training_output_dir, use_folds=use_folds, checkpoint_name=checkpoint_name
845+
)
846+
predictor.predict_from_files(
847+
list_of_lists_or_source_folder=list_of_lists_or_source_folder,
848+
output_folder_or_list_of_truncated_output_files=output_folder,
846849
save_probabilities=save_probabilities,
847850
overwrite=overwrite,
848-
checkpoint_name=checkpoint_name,
849851
num_processes_preprocessing=n_processes_preprocessing,
850852
num_processes_segmentation_export=n_processes_segmentation_export,
851853
folder_with_segs_from_prev_stage=folder_with_segs_from_prev_stage,

0 commit comments

Comments
 (0)