class_docstr: ``nnUNetV2Runner`` provides an interface in MONAI to use `nnU-Net` V2 library to analyze, train, and evaluate
  neural networks for medical image segmentation tasks.
  
  ``nnUNetV2Runner`` can be used in two ways:
  
  #. with one line of code to execute the complete pipeline.
  #. with a series of commands to run each modules in the pipeline.
  
  The output of the interface is a directory that contains:
  
  #. converted dataset met the requirement of nnU-Net V2
  #. data analysis results
  #. checkpoints from the trained U-Net models
  #. validation accuracy in each fold of cross-validation
  #. the predictions on the testing datasets from the final algorithm ensemble and potential post-processing
  
  Args:
      input_config: the configuration dictionary or the file path to the configuration in the form of YAML.
          The keys required in the configuration are:
          - ``"datalist"``: File path to the datalist for the train/testing splits
          - ``"dataroot"``: File path to the dataset
          - ``"modality"``: Imaging modality, e.g. "CT", ["T2", "ADC"]
          Currently, the configuration supports these optional keys:
          - ``"nnunet_raw"``: File path that will be written to env variable for nnU-Net
          - ``"nnunet_preprocessed"``: File path that will be written to env variable for nnU-Net
          - ``"nnunet_results"``: File path that will be written to env variable for nnU-Net
          - ``"nnUNet_trained_models"``
          - ``"dataset_name_or_id"``: Name or Integer ID of the dataset
          If an optional key is not specified, then the pipeline will use the default values.
      trainer_class_name: the trainer class names offered by nnUNetV2 exhibit variations in training duration.
          Default: "nnUNetTrainer". Other options: "nnUNetTrainer_Xepoch". X could be one of 1,5,10,20,50,100,
          250,2000,4000,8000.
      export_validation_probabilities: True to save softmax predictions from final validation as npz
          files (in addition to predicted segmentations). Needed for finding the best ensemble.
          Default: True.
      work_dir: working directory to save the intermediate and final results.
  
  Examples:
      - Use the one-liner to start the nnU-Net workflow
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner run --input_config ./input.yaml
  
      - Use `convert_dataset` to prepare the data to meet nnU-Net requirements, generate dataset JSON file,
          and copy the dataset to a location specified by ``nnunet_raw`` in the input config file
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner convert_dataset --input_config="./input.yaml"
  
      - `convert_msd_dataset` is an alternative option to prepare the data if the dataset is MSD.
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner convert_msd_dataset \
              --input_config "./input.yaml" --data_dir "/path/to/Task09_Spleen"
  
      - experiment planning and data pre-processing
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner plan_and_process --input_config "./input.yaml"
  
      - training all 20 models using all GPUs available.
          "CUDA_VISIBLE_DEVICES" environment variable is not supported.
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner train --input_config "./input.yaml"
  
      - training a single model on a single GPU for 5 epochs. Here ``config`` is used to specify the configuration.
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner train_single_model --input_config "./input.yaml" \
              --config "3d_fullres" \
              --fold 0 \
              --gpu_id 0 \
              --trainer_class_name "nnUNetTrainer_5epochs" \
              --export_validation_probabilities True
  
      - training for all 20 models (4 configurations by 5 folds) on 2 GPUs
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner train --input_config "./input.yaml" --gpu_id_for_all "0,1"
  
      - 5-fold training for a single model on 2 GPUs. Here ``configs`` is used to specify the configurations.
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner train --input_config "./input.yaml" \
              --configs "3d_fullres" \
              --trainer_class_name "nnUNetTrainer_5epochs" \
              --export_validation_probabilities True \
              --gpu_id_for_all "0,1"
  
      - find the best configuration
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner find_best_configuration --input_config "./input.yaml"
  
      - predict, ensemble, and post-process
  
      .. code-block:: bash
  
          python -m monai.apps.nnunet nnUNetV2Runner predict_ensemble_postprocessing --input_config "./input.yaml"
class_docstr_tok: ["``","nnUNetV2Runner","``","provides","an","interface","in","MONAI","to","use","`","nnU-Net","`","V2","library","to","analyze",",","train",",","and","evaluate","neural","networks","for","medical","image","segmentation","tasks",".","``","nnUNetV2Runner","``","can","be","used","in","two","ways",":","#",".","with","one","line","of","code","to","execute","the","complete","pipeline",".","#",".","with","a","series","of","commands","to","run","each","modules","in","the","pipeline",".","The","output","of","the","interface","is","a","directory","that","contains",":","#",".","converted","dataset","met","the","requirement","of","nnU-Net","V2","#",".","data","analysis","results","#",".","checkpoints","from","the","trained","U-Net","models","#",".","validation","accuracy","in","each","fold","of","cross-validation","#",".","the","predictions","on","the","testing","datasets","from","the","final","algorithm","ensemble","and","potential","post-processing","Args",":","input_config",":","the","configuration","dictionary","or","the","file","path","to","the","configuration","in","the","form","of","YAML",".","The","keys","required","in","the","configuration","are",":","-","``","``","datalist","''","``",":","File","path","to","the","datalist","for","the","train\/testing","splits","-","``","``","dataroot","''","``",":","File","path","to","the","dataset","-","``","``","modality","''","``",":","Imaging","modality",",","e.g",".","``","CT","''",",","[","``","T2","''",",","``","ADC","''","]","Currently",",","the","configuration","supports","these","optional","keys",":","-","``","``","nnunet_raw","''","``",":","File","path","that","will","be","written","to","env","variable","for","nnU-Net","-","``","``","nnunet_preprocessed","''","``",":","File","path","that","will","be","written","to","env","variable","for","nnU-Net","-","``","``","nnunet_results","''","``",":","File","path","that","will","be","written","to","env","variable","for","nnU-Net","-","``","``","nnUNet_trained_models","''","``","-","``","``","dataset_name_or_id","''","``",":","Name","or","Integer","ID","of","the","dataset","If","an","optional","key","is","not","specified",",","then","the","pipeline","will","use","the","default","values",".","trainer_class_name",":","the","trainer","class","names","offered","by","nnUNetV2","exhibit","variations","in","training","duration",".","Default",":","``","nnUNetTrainer","''",".","Other","options",":","``","nnUNetTrainer_Xepoch","''",".","X","could","be","one","of","1,5,10,20,50,100",",","250,2000,4000,8000.","export_validation_probabilities",":","True","to","save","softmax","predictions","from","final","validation","as","npz","files","(","in","addition","to","predicted","segmentations",")",".","Needed","for","finding","the","best","ensemble",".","Default",":","True",".","work_dir",":","working","directory","to","save","the","intermediate","and","final","results",".","Examples",":","-","Use","the","one-liner","to","start","the","nnU-Net","workflow","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","run","--","input_config",".\/input.yaml","-","Use","`","convert_dataset","`","to","prepare","the","data","to","meet","nnU-Net","requirements",",","generate","dataset","JSON","file",",","and","copy","the","dataset","to","a","location","specified","by","``","nnunet_raw","``","in","the","input","config","file","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","convert_dataset","--","input_config=","''",".\/input.yaml","''","-","`","convert_msd_dataset","`","is","an","alternative","option","to","prepare","the","data","if","the","dataset","is","MSD",".","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","convert_msd_dataset","\\","--","input_config","``",".\/input.yaml","''","--","data_dir","``","\/path\/to\/Task09_Spleen","''","-","experiment","planning","and","data","pre-processing","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","plan_and_process","--","input_config","``",".\/input.yaml","''","-","training","all","20","models","using","all","GPUs","available",".","``","CUDA_VISIBLE_DEVICES","''","environment","variable","is","not","supported",".","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","train","--","input_config","``",".\/input.yaml","''","-","training","a","single","model","on","a","single","GPU","for","5","epochs",".","Here","``","config","``","is","used","to","specify","the","configuration",".","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","train_single_model","--","input_config","``",".\/input.yaml","''","\\","--","config","``","3d_fullres","''","\\","--","fold","0","\\","--","gpu_id","0","\\","--","trainer_class_name","``","nnUNetTrainer_5epochs","''","\\","--","export_validation_probabilities","True","-","training","for","all","20","models","(","4","configurations","by","5","folds",")","on","2","GPUs","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","train","--","input_config","``",".\/input.yaml","''","--","gpu_id_for_all","``","0,1","''","-","5-fold","training","for","a","single","model","on","2","GPUs",".","Here","``","configs","``","is","used","to","specify","the","configurations",".","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","train","--","input_config","``",".\/input.yaml","''","\\","--","configs","``","3d_fullres","''","\\","--","trainer_class_name","``","nnUNetTrainer_5epochs","''","\\","--","export_validation_probabilities","True","\\","--","gpu_id_for_all","``","0,1","''","-","find","the","best","configuration","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","find_best_configuration","--","input_config","``",".\/input.yaml","''","-","predict",",","ensemble",",","and","post-process","..","code-block",":",":","bash","python","-m","monai.apps.nnunet","nnUNetV2Runner","predict_ensemble_postprocessing","--","input_config","``",".\/input.yaml","''"]
docstr: Use this to run inference with nnU-Net. This function is used when you want to manually specify a folder containing
      a trained nnU-Net model. This is useful when the nnunet environment variables (nnUNet_results) are not set.
  
  Args:
      list_of_lists_or_source_folder: input folder. Remember to use the correct channel numberings for
          your files (_0000 etc). File endings must be the same as the training dataset!
      output_folder: Output folder. If it does not exist it will be created. Predicted segmentations will
          have the same name as their source images.
      model_training_output_dir: folder in which the trained model is. Must have subfolders fold_X for the
          different folds you trained.
      use_folds: specify the folds of the trained model that should be used for prediction
          Default: (0, 1, 2, 3, 4).
      tile_step_size: step size for sliding window prediction. The larger it is the faster but less accurate
          the prediction. Default: 0.5. Cannot be larger than 1. We recommend the default.
      use_gaussian: use Gaussian smoothing as test-time augmentation.
      use_mirroring: use mirroring/flipping as test-time augmentation.
      verbose: set this if you like being talked to. You will have to be a good listener/reader.
      save_probabilities: set this to export predicted class "probabilities". Required if you want to ensemble
          multiple configurations.
      overwrite: overwrite an existing previous prediction (will not overwrite existing files)
      checkpoint_name: name of the checkpoint you want to use. Default: checkpoint_final.pth.
      folder_with_segs_from_prev_stage: folder containing the predictions of the previous stage.
          Required for cascaded models.
      num_parts: number of separate nnUNetv2_predict call that you will be making. Default: 1 (= this one
          call predicts everything).
      part_id: if multiple nnUNetv2_predict exist, which one is this? IDs start with 0 can end with
          num_parts - 1. So when you submit 5 nnUNetv2_predict calls you need to set -num_parts
          5 and use -part_id 0, 1, 2, 3 and 4.
      num_processes_preprocessing: out-of-RAM issues.
      num_processes_segmentation_export: Number of processes used for segmentation export.
          More is not always better. Beware of out-of-RAM issues.
      gpu_id: which GPU to use for prediction.
docstr_tok: ["Use","this","to","run","inference","with","nnU-Net",".","This","function","is","used","when","you","want","to","manually","specify","a","folder","containing","a","trained","nnU-Net","model",".","This","is","useful","when","the","nnunet","environment","variables","(","nnUNet_results",")","are","not","set",".","Args",":","list_of_lists_or_source_folder",":","input","folder",".","Remember","to","use","the","correct","channel","numberings","for","your","files","(","_0000","etc",")",".","File","endings","must","be","the","same","as","the","training","dataset","!","output_folder",":","Output","folder",".","If","it","does","not","exist","it","will","be","created",".","Predicted","segmentations","will","have","the","same","name","as","their","source","images",".","model_training_output_dir",":","folder","in","which","the","trained","model","is",".","Must","have","subfolders","fold_X","for","the","different","folds","you","trained",".","use_folds",":","specify","the","folds","of","the","trained","model","that","should","be","used","for","prediction","Default",":","(","0",",","1",",","2",",","3",",","4",")",".","tile_step_size",":","step","size","for","sliding","window","prediction",".","The","larger","it","is","the","faster","but","less","accurate","the","prediction",".","Default",":","0.5",".","Can","not","be","larger","than","1",".","We","recommend","the","default",".","use_gaussian",":","use","Gaussian","smoothing","as","test-time","augmentation",".","use_mirroring",":","use","mirroring\/flipping","as","test-time","augmentation",".","verbose",":","set","this","if","you","like","being","talked","to",".","You","will","have","to","be","a","good","listener\/reader",".","save_probabilities",":","set","this","to","export","predicted","class","``","probabilities","''",".","Required","if","you","want","to","ensemble","multiple","configurations",".","overwrite",":","overwrite","an","existing","previous","prediction","(","will","not","overwrite","existing","files",")","checkpoint_name",":","name","of","the","checkpoint","you","want","to","use",".","Default",":","checkpoint_final.pth",".","folder_with_segs_from_prev_stage",":","folder","containing","the","predictions","of","the","previous","stage",".","Required","for","cascaded","models",".","num_parts",":","number","of","separate","nnUNetv2_predict","call","that","you","will","be","making",".","Default",":","1","(","=","this","one","call","predicts","everything",")",".","part_id",":","if","multiple","nnUNetv2_predict","exist",",","which","one","is","this","?","IDs","start","with","0","can","end","with","num_parts","-","1",".","So","when","you","submit","5","nnUNetv2_predict","calls","you","need","to","set","-num_parts","5","and","use","-part_id","0",",","1",",","2",",","3","and","4.","num_processes_preprocessing",":","out-of-RAM","issues",".","num_processes_segmentation_export",":","Number","of","processes","used","for","segmentation","export",".","More","is","not","always","better",".","Beware","of","out-of-RAM","issues",".","gpu_id",":","which","GPU","to","use","for","prediction","."]
code: def predict(
      self,
      list_of_lists_or_source_folder: str | list[list[str]],
      output_folder: str,
      model_training_output_dir: str,
      use_folds: tuple[int, ...] | str | None = None,
      tile_step_size: float = 0.5,
      use_gaussian: bool = True,
      use_mirroring: bool = True,
      perform_everything_on_gpu: bool = True,
      verbose: bool = True,
      save_probabilities: bool = False,
      overwrite: bool = True,
      checkpoint_name: str = "checkpoint_final.pth",
      folder_with_segs_from_prev_stage: str | None = None,
      num_parts: int = 1,
      part_id: int = 0,
      num_processes_preprocessing: int = -1,
      num_processes_segmentation_export: int = -1,
      gpu_id: int = 0,
  ) -> None:
      """
      Use this to run inference with nnU-Net. This function is used when you want to manually specify a folder containing
          a trained nnU-Net model. This is useful when the nnunet environment variables (nnUNet_results) are not set.
  
      Args:
          list_of_lists_or_source_folder: input folder. Remember to use the correct channel numberings for
              your files (_0000 etc). File endings must be the same as the training dataset!
          output_folder: Output folder. If it does not exist it will be created. Predicted segmentations will
              have the same name as their source images.
          model_training_output_dir: folder in which the trained model is. Must have subfolders fold_X for the
              different folds you trained.
          use_folds: specify the folds of the trained model that should be used for prediction
              Default: (0, 1, 2, 3, 4).
          tile_step_size: step size for sliding window prediction. The larger it is the faster but less accurate
              the prediction. Default: 0.5. Cannot be larger than 1. We recommend the default.
          use_gaussian: use Gaussian smoothing as test-time augmentation.
          use_mirroring: use mirroring/flipping as test-time augmentation.
          verbose: set this if you like being talked to. You will have to be a good listener/reader.
          save_probabilities: set this to export predicted class "probabilities". Required if you want to ensemble
              multiple configurations.
          overwrite: overwrite an existing previous prediction (will not overwrite existing files)
          checkpoint_name: name of the checkpoint you want to use. Default: checkpoint_final.pth.
          folder_with_segs_from_prev_stage: folder containing the predictions of the previous stage.
              Required for cascaded models.
          num_parts: number of separate nnUNetv2_predict call that you will be making. Default: 1 (= this one
              call predicts everything).
          part_id: if multiple nnUNetv2_predict exist, which one is this? IDs start with 0 can end with
              num_parts - 1. So when you submit 5 nnUNetv2_predict calls you need to set -num_parts
              5 and use -part_id 0, 1, 2, 3 and 4.
          num_processes_preprocessing: out-of-RAM issues.
          num_processes_segmentation_export: Number of processes used for segmentation export.
              More is not always better. Beware of out-of-RAM issues.
          gpu_id: which GPU to use for prediction.
      """
      os.environ["CUDA_VISIBLE_DEVICES"] = f"{gpu_id}"
  
      from nnunetv2.inference.predict_from_raw_data import (
          predict_from_raw_data,
      )
  
      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,
          tile_step_size=tile_step_size,
          use_gaussian=use_gaussian,
          use_mirroring=use_mirroring,
          perform_everything_on_gpu=perform_everything_on_gpu,
          verbose=verbose,
          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,
          num_parts=num_parts,
          part_id=part_id,
      )
  
imports: from __future__ import annotations
  import glob
  import os
  import subprocess
  from typing import Any
  import monai
  from monai.apps.nnunet.utils import NNUNETMode
  from monai.apps.nnunet.utils import analyze_data, create_new_data_copy, create_new_dataset_json
  from monai.bundle import ConfigParser
  from monai.utils import ensure_tuple, optional_import
label_desc: Use image node_id 15 for calling the nnUNetV2Runner obj's underlying member method code with example usage: obj.predict(list_of_lists_or_source_folder, output_folder, model_training_output_dir, use_folds, tile_step_size, use_gaussian, use_mirroring, perform_everything_on_gpu, verbose, save_probabilities, overwrite, checkpoint_name, folder_with_segs_from_prev_stage, num_parts, part_id, num_processes_preprocessing, num_processes_segmentation_export, gpu_id) without return types