Skip to content

Commit

Permalink
add nnunetv2 runner class (#5987)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people authored Mar 20, 2023
1 parent 81b25ae commit eed660c
Show file tree
Hide file tree
Showing 9 changed files with 1,151 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/source/apps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ FastMRIReader

`auto3dseg`
-----------

.. automodule:: monai.apps.auto3dseg
:members:
:imported-members:

`nnUNet`
--------
.. automodule:: monai.apps.nnunet.__main__

.. autoclass:: monai.apps.nnunet.nnUNetV2Runner
:members:
1 change: 1 addition & 0 deletions monai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"(^(monai._C))",
"(.*(__main__)$)",
"(.*(video_dataset)$)",
"(.*(nnunet).*$)",
]
)

Expand Down
15 changes: 15 additions & 0 deletions monai/apps/nnunet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

from .nnunetv2_runner import nnUNetV2Runner
from .utils import NNUNETMode, analyze_data, create_new_data_copy, create_new_dataset_json
97 changes: 97 additions & 0 deletions monai/apps/nnunet/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Examples:
- User can use the one-liner to start the nnU-Net workflow
.. code-block:: bash
python -m monai.apps.nnunet nnUNetV2Runner run --input "./input.yaml"
- convert dataset
.. code-block:: bash
python -m monai.apps.nnunet nnUNetRunner convert_dataset --input "./input_new.yaml"
- convert msd datasets
.. code-block:: bash
python -m monai.apps.nnunet nnUNetRunner convert_msd_dataset \\
--input "./input.yaml" --data_dir "Task05_Prostate"
- experiment planning and data pre-processing
.. code-block:: bash
python -m monai.apps.nnunet nnUNetRunner plan_and_process --input "./input.yaml"
- single-gpu training for all 20 models
.. code-block:: bash
python -m monai.apps.nnunet nnUNetV2Runner train --input "./input.yaml"
- single-gpu training for a single model
.. code-block:: bash
python -m monai.apps.nnunet nnUNetV2Runner train_single_model --input "./input.yaml" \\
--config "3d_fullres" \\
--fold 0 \\
--trainer_class_name "nnUNetTrainer_5epochs" \\
--export_validation_probabilities true
- multi-gpu training for all 20 models
.. code-block:: bash
export CUDA_VISIBLE_DEVICES=0,1 # optional
python -m monai.apps.nnunet nnUNetV2Runner train --input "./input.yaml" --num_gpus 2
- multi-gpu training for a single model
.. code-block:: bash
export CUDA_VISIBLE_DEVICES=0,1 # optional
python -m monai.apps.nnunet nnUNetV2Runner train_single_model --input "./input.yaml" \\
--config "3d_fullres" \\
--fold 0 \\
--trainer_class_name "nnUNetTrainer_5epochs" \\
--export_validation_probabilities true \\
--num_gpus 2
- find best configuration
.. code-block:: bash
python -m monai.apps.nnunet nnUNetRunner find_best_configuration --input "./input.yaml"
- predict, ensemble, and post-process
.. code-block:: bash
python -m monai.apps.nnunet nnUNetRunner predict_ensemble_postprocessing --input "./input.yaml"
"""


from __future__ import annotations

from monai.apps.nnunet.nnunetv2_runner import nnUNetV2Runner

if __name__ == "__main__":
from monai.utils import optional_import

fire, _ = optional_import("fire")
fire.Fire({"nnUNetV2Runner": nnUNetV2Runner})
Loading

0 comments on commit eed660c

Please sign in to comment.