|
13 | 13 | import os |
14 | 14 | import shutil |
15 | 15 | from pathlib import Path |
16 | | -from typing import Any, Optional, Union |
| 16 | +from typing import Any |
17 | 17 |
|
18 | 18 | import numpy as np |
19 | 19 | import torch |
|
36 | 36 |
|
37 | 37 |
|
38 | 38 | def get_nnunet_trainer( |
39 | | - dataset_name_or_id: Union[str, int], |
| 39 | + dataset_name_or_id: str | int, |
40 | 40 | configuration: str, |
41 | | - fold: Union[int, str], |
| 41 | + fold: int | str, |
42 | 42 | trainer_class_name: str = "nnUNetTrainer", |
43 | 43 | plans_identifier: str = "nnUNetPlans", |
44 | 44 | use_compressed_data: bool = False, |
45 | 45 | continue_training: bool = False, |
46 | 46 | only_run_validation: bool = False, |
47 | 47 | disable_checkpointing: bool = False, |
48 | 48 | device: str = "cuda", |
49 | | - pretrained_model: Optional[str] = None, |
| 49 | + pretrained_model: str | None = None, |
50 | 50 | ) -> Any: # type: ignore |
51 | 51 | """ |
52 | 52 | Get the nnUNet trainer instance based on the provided configuration. |
@@ -166,7 +166,7 @@ class ModelnnUNetWrapper(torch.nn.Module): |
166 | 166 | restoring network architecture, and setting up the predictor for inference. |
167 | 167 | """ |
168 | 168 |
|
169 | | - def __init__(self, predictor: object, model_folder: Union[str, Path], model_name: str = "model.pt"): # type: ignore |
| 169 | + def __init__(self, predictor: object, model_folder: str | Path, model_name: str = "model.pt"): # type: ignore |
170 | 170 | super().__init__() |
171 | 171 | self.predictor = predictor |
172 | 172 |
|
@@ -294,7 +294,7 @@ def forward(self, x: MetaTensor) -> MetaTensor: |
294 | 294 | return MetaTensor(out_tensor, meta=x.meta) |
295 | 295 |
|
296 | 296 |
|
297 | | -def get_nnunet_monai_predictor(model_folder: Union[str, Path], model_name: str = "model.pt") -> ModelnnUNetWrapper: |
| 297 | +def get_nnunet_monai_predictor(model_folder: str | Path, model_name: str = "model.pt") -> ModelnnUNetWrapper: |
298 | 298 | """ |
299 | 299 | Initializes and returns a `nnUNetMONAIModelWrapper` containing the corresponding `nnUNetPredictor`. |
300 | 300 | The model folder should contain the following files, created during training: |
@@ -426,9 +426,9 @@ def get_network_from_nnunet_plans( |
426 | 426 | plans_file: str, |
427 | 427 | dataset_file: str, |
428 | 428 | configuration: str, |
429 | | - model_ckpt: Optional[str] = None, |
| 429 | + model_ckpt: str | None = None, |
430 | 430 | model_key_in_ckpt: str = "model", |
431 | | -) -> Union[torch.nn.Module, Any]: |
| 431 | +) -> torch.nn.Module | Any: |
432 | 432 | """ |
433 | 433 | Load and initialize a nnUNet network based on nnUNet plans and configuration. |
434 | 434 |
|
@@ -518,7 +518,7 @@ def convert_monai_bundle_to_nnunet(nnunet_config: dict, bundle_root_folder: str, |
518 | 518 | from nnunetv2.utilities.dataset_name_id_conversion import maybe_convert_to_dataset_name |
519 | 519 |
|
520 | 520 | def subfiles( |
521 | | - folder: Union[str, Path], prefix: Optional[str] = None, suffix: Optional[str] = None, sort: bool = True |
| 521 | + folder: str | Path, prefix: str | None = None, suffix: str | None = None, sort: bool = True |
522 | 522 | ) -> list[str]: |
523 | 523 | res = [ |
524 | 524 | i.name |
|
0 commit comments