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: Generate a configuration file that specifies the details of the experiment.
  
  Args:
      pl: [OPTIONAL] Name of the Experiment Planner class that should be used. Default is "ExperimentPlanner".
          Note: There is no longer a distinction between 2d and 3d planner. It's an all-in-one solution now.
      gpu_memory_target: [OPTIONAL] DANGER ZONE! Sets a custom GPU memory target. Default: 8 [GB].
          Changing this will affect patch and batch size and will definitely affect your models' performance!
          Only use this if you really know what you are doing and NEVER use this without running the
          default nnU-Net first (as a baseline).
      preprocessor_name: [OPTIONAL] DANGER ZONE! Sets a custom preprocessor class. This class must be located in
          nnunetv2.preprocessing. Default: "DefaultPreprocessor". Changing this may affect your models'
          performance! Only use this if you really know what you are doing and NEVER use this without running the
          default nnU-Net first (as a baseline).
      overwrite_target_spacing: [OPTIONAL] DANGER ZONE! Sets a custom target spacing for the 3d_fullres
          and 3d_cascade_fullres configurations. Default: None [no changes]. Changing this will affect
          image size and potentially patch and batch size. This will definitely affect your models' performance!
          Only use this if you really know what you are doing and NEVER use this without running the
          default nnU-Net first (as a baseline). Changing the target spacing for the other configurations
          is currently not implemented. New target spacing must be a list of three numbers!
      overwrite_plans_name: [OPTIONAL] DANGER ZONE! If you used -gpu_memory_target, -preprocessor_name or
          -overwrite_target_spacing it is best practice to use -overwrite_plans_name to generate
          a differently named plans file such that the nnunet default plans are not overwritten.
          You will then need to specify your custom plan.
docstr_tok: ["Generate","a","configuration","file","that","specifies","the","details","of","the","experiment",".","Args",":","pl",":","[","OPTIONAL","]","Name","of","the","Experiment","Planner","class","that","should","be","used",".","Default","is","``","ExperimentPlanner","''",".","Note",":","There","is","no","longer","a","distinction","between","2d","and","3d","planner",".","It","'s","an","all-in-one","solution","now",".","gpu_memory_target",":","[","OPTIONAL","]","DANGER","ZONE","!","Sets","a","custom","GPU","memory","target",".","Default",":","8","[","GB","]",".","Changing","this","will","affect","patch","and","batch","size","and","will","definitely","affect","your","models","'","performance","!","Only","use","this","if","you","really","know","what","you","are","doing","and","NEVER","use","this","without","running","the","default","nnU-Net","first","(","as","a","baseline",")",".","preprocessor_name",":","[","OPTIONAL","]","DANGER","ZONE","!","Sets","a","custom","preprocessor","class",".","This","class","must","be","located","in","nnunetv2.preprocessing",".","Default",":","``","DefaultPreprocessor","''",".","Changing","this","may","affect","your","models'","performance","!","Only","use","this","if","you","really","know","what","you","are","doing","and","NEVER","use","this","without","running","the","default","nnU-Net","first","(","as","a","baseline",")",".","overwrite_target_spacing",":","[","OPTIONAL","]","DANGER","ZONE","!","Sets","a","custom","target","spacing","for","the","3d_fullres","and","3d_cascade_fullres","configurations",".","Default",":","None","[","no","changes","]",".","Changing","this","will","affect","image","size","and","potentially","patch","and","batch","size",".","This","will","definitely","affect","your","models","'","performance","!","Only","use","this","if","you","really","know","what","you","are","doing","and","NEVER","use","this","without","running","the","default","nnU-Net","first","(","as","a","baseline",")",".","Changing","the","target","spacing","for","the","other","configurations","is","currently","not","implemented",".","New","target","spacing","must","be","a","list","of","three","numbers","!","overwrite_plans_name",":","[","OPTIONAL","]","DANGER","ZONE","!","If","you","used","-gpu_memory_target",",","-preprocessor_name","or","-overwrite_target_spacing","it","is","best","practice","to","use","-overwrite_plans_name","to","generate","a","differently","named","plans","file","such","that","the","nnunet","default","plans","are","not","overwritten",".","You","will","then","need","to","specify","your","custom","plan","."]
code: def plan_experiments(
      self,
      pl: str = "ExperimentPlanner",
      gpu_memory_target: float = 8,
      preprocessor_name: str = "DefaultPreprocessor",
      overwrite_target_spacing: Any = None,
      overwrite_plans_name: str = "nnUNetPlans",
  ) -> None:
      """
      Generate a configuration file that specifies the details of the experiment.
  
      Args:
          pl: [OPTIONAL] Name of the Experiment Planner class that should be used. Default is "ExperimentPlanner".
              Note: There is no longer a distinction between 2d and 3d planner. It's an all-in-one solution now.
          gpu_memory_target: [OPTIONAL] DANGER ZONE! Sets a custom GPU memory target. Default: 8 [GB].
              Changing this will affect patch and batch size and will definitely affect your models' performance!
              Only use this if you really know what you are doing and NEVER use this without running the
              default nnU-Net first (as a baseline).
          preprocessor_name: [OPTIONAL] DANGER ZONE! Sets a custom preprocessor class. This class must be located in
              nnunetv2.preprocessing. Default: "DefaultPreprocessor". Changing this may affect your models'
              performance! Only use this if you really know what you are doing and NEVER use this without running the
              default nnU-Net first (as a baseline).
          overwrite_target_spacing: [OPTIONAL] DANGER ZONE! Sets a custom target spacing for the 3d_fullres
              and 3d_cascade_fullres configurations. Default: None [no changes]. Changing this will affect
              image size and potentially patch and batch size. This will definitely affect your models' performance!
              Only use this if you really know what you are doing and NEVER use this without running the
              default nnU-Net first (as a baseline). Changing the target spacing for the other configurations
              is currently not implemented. New target spacing must be a list of three numbers!
          overwrite_plans_name: [OPTIONAL] DANGER ZONE! If you used -gpu_memory_target, -preprocessor_name or
              -overwrite_target_spacing it is best practice to use -overwrite_plans_name to generate
              a differently named plans file such that the nnunet default plans are not overwritten.
              You will then need to specify your custom plan.
      """
      from nnunetv2.experiment_planning.plan_and_preprocess_api import (
          plan_experiments,
      )
  
      logger.info("Experiment planning...")
      plan_experiments(
          [int(self.dataset_name_or_id)],
          pl,
          gpu_memory_target,
          preprocessor_name,
          overwrite_target_spacing,
          overwrite_plans_name,
      )
  
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 5 for calling the nnUNetV2Runner obj's underlying member method code with example usage: obj.plan_experiments(pl, gpu_memory_target, preprocessor_name, overwrite_target_spacing, overwrite_plans_name) without return types