Skip to content
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

Update test_nnunetv2runner #7483

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions monai/apps/nnunet/nnunetv2_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class nnUNetV2Runner: # noqa: N801
"""
``nnUNetV2Runner`` provides an interface in MONAI to use `nnU-Net` V2 library to analyze, train, and evaluate
neural networks for medical image segmentation tasks.
A version of nnunetv2 higher than 2.2 is needed for this class.

``nnUNetV2Runner`` can be used in two ways:

Expand Down Expand Up @@ -770,7 +771,7 @@ def find_best_configuration(
def predict(
self,
list_of_lists_or_source_folder: str | list[list[str]],
output_folder: str,
output_folder: str | None | list[str],
model_training_output_dir: str,
use_folds: tuple[int, ...] | str | None = None,
tile_step_size: float = 0.5,
Expand Down Expand Up @@ -824,28 +825,29 @@ def predict(
"""
os.environ["CUDA_VISIBLE_DEVICES"] = f"{gpu_id}"

from nnunetv2.inference.predict_from_raw_data import predict_from_raw_data
from nnunetv2.inference.predict_from_raw_data import nnUNetPredictor

n_processes_preprocessing = (
self.default_num_processes if num_processes_preprocessing < 0 else num_processes_preprocessing
)
n_processes_segmentation_export = (
self.default_num_processes if num_processes_segmentation_export < 0 else num_processes_segmentation_export
)

predict_from_raw_data(
list_of_lists_or_source_folder=list_of_lists_or_source_folder,
output_folder=output_folder,
model_training_output_dir=model_training_output_dir,
use_folds=use_folds,
predictor = nnUNetPredictor(
tile_step_size=tile_step_size,
use_gaussian=use_gaussian,
use_mirroring=use_mirroring,
perform_everything_on_gpu=perform_everything_on_gpu,
perform_everything_on_device=perform_everything_on_gpu,
verbose=verbose,
)
predictor.initialize_from_trained_model_folder(
model_training_output_dir=model_training_output_dir, use_folds=use_folds, checkpoint_name=checkpoint_name
)
predictor.predict_from_files(
list_of_lists_or_source_folder=list_of_lists_or_source_folder,
output_folder_or_list_of_truncated_output_files=output_folder,
save_probabilities=save_probabilities,
overwrite=overwrite,
checkpoint_name=checkpoint_name,
num_processes_preprocessing=n_processes_preprocessing,
num_processes_segmentation_export=n_processes_segmentation_export,
folder_with_segs_from_prev_stage=folder_with_segs_from_prev_stage,
Expand Down
Loading