Skip to content

Commit eed660c

Browse files
dongyang0122dongypre-commit-ci[bot]wyli
authored
add nnunetv2 runner class (#5987)
Signed-off-by: dongy <dongy@nvidia.com> ### Description Adding nnunetv2 runner class to launch different steps in nnunet via Python APIs. ### 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: dongy <dongy@nvidia.com> Signed-off-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: dongy <dongy@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li <wenqil@nvidia.com>
1 parent 81b25ae commit eed660c

File tree

9 files changed

+1151
-3
lines changed

9 files changed

+1151
-3
lines changed

docs/source/apps.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ FastMRIReader
274274

275275
`auto3dseg`
276276
-----------
277-
278277
.. automodule:: monai.apps.auto3dseg
279278
:members:
280279
:imported-members:
280+
281+
`nnUNet`
282+
--------
283+
.. automodule:: monai.apps.nnunet.__main__
284+
285+
.. autoclass:: monai.apps.nnunet.nnUNetV2Runner
286+
:members:

monai/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"(^(monai._C))",
5151
"(.*(__main__)$)",
5252
"(.*(video_dataset)$)",
53+
"(.*(nnunet).*$)",
5354
]
5455
)
5556

monai/apps/nnunet/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
from __future__ import annotations
13+
14+
from .nnunetv2_runner import nnUNetV2Runner
15+
from .utils import NNUNETMode, analyze_data, create_new_data_copy, create_new_dataset_json

monai/apps/nnunet/__main__.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
"""
13+
Examples:
14+
- User can use the one-liner to start the nnU-Net workflow
15+
16+
.. code-block:: bash
17+
18+
python -m monai.apps.nnunet nnUNetV2Runner run --input "./input.yaml"
19+
20+
- convert dataset
21+
22+
.. code-block:: bash
23+
24+
python -m monai.apps.nnunet nnUNetRunner convert_dataset --input "./input_new.yaml"
25+
26+
- convert msd datasets
27+
28+
.. code-block:: bash
29+
30+
python -m monai.apps.nnunet nnUNetRunner convert_msd_dataset \\
31+
--input "./input.yaml" --data_dir "Task05_Prostate"
32+
33+
- experiment planning and data pre-processing
34+
35+
.. code-block:: bash
36+
37+
python -m monai.apps.nnunet nnUNetRunner plan_and_process --input "./input.yaml"
38+
39+
- single-gpu training for all 20 models
40+
41+
.. code-block:: bash
42+
43+
python -m monai.apps.nnunet nnUNetV2Runner train --input "./input.yaml"
44+
45+
- single-gpu training for a single model
46+
47+
.. code-block:: bash
48+
49+
python -m monai.apps.nnunet nnUNetV2Runner train_single_model --input "./input.yaml" \\
50+
--config "3d_fullres" \\
51+
--fold 0 \\
52+
--trainer_class_name "nnUNetTrainer_5epochs" \\
53+
--export_validation_probabilities true
54+
55+
- multi-gpu training for all 20 models
56+
57+
.. code-block:: bash
58+
59+
export CUDA_VISIBLE_DEVICES=0,1 # optional
60+
python -m monai.apps.nnunet nnUNetV2Runner train --input "./input.yaml" --num_gpus 2
61+
62+
- multi-gpu training for a single model
63+
64+
.. code-block:: bash
65+
66+
export CUDA_VISIBLE_DEVICES=0,1 # optional
67+
python -m monai.apps.nnunet nnUNetV2Runner train_single_model --input "./input.yaml" \\
68+
--config "3d_fullres" \\
69+
--fold 0 \\
70+
--trainer_class_name "nnUNetTrainer_5epochs" \\
71+
--export_validation_probabilities true \\
72+
--num_gpus 2
73+
74+
- find best configuration
75+
76+
.. code-block:: bash
77+
78+
python -m monai.apps.nnunet nnUNetRunner find_best_configuration --input "./input.yaml"
79+
80+
- predict, ensemble, and post-process
81+
82+
.. code-block:: bash
83+
84+
python -m monai.apps.nnunet nnUNetRunner predict_ensemble_postprocessing --input "./input.yaml"
85+
86+
"""
87+
88+
89+
from __future__ import annotations
90+
91+
from monai.apps.nnunet.nnunetv2_runner import nnUNetV2Runner
92+
93+
if __name__ == "__main__":
94+
from monai.utils import optional_import
95+
96+
fire, _ = optional_import("fire")
97+
fire.Fire({"nnUNetV2Runner": nnUNetV2Runner})

0 commit comments

Comments
 (0)