class_docstr: The base class of Ensemble methods
class_docstr_tok: ["The","base","class","of","Ensemble","methods"]
docstr: Use the ensembled model to predict result.
  
  Args:
      pred_param: prediction parameter dictionary. The key has two groups: the first one will be consumed
          in this function, and the second group will be passed to the `InferClass` to override the
          parameters of the class functions.
          The first group contains:
  
              - ``"infer_files"``: file paths to the images to read in a list.
              - ``"files_slices"``: a value type of `slice`. The files_slices will slice the ``"infer_files"`` and
                only make prediction on the infer_files[file_slices].
              - ``"mode"``: ensemble mode. Currently "mean" and "vote" (majority voting) schemes are supported.
              - ``"image_save_func"``: a dictionary used to instantiate the ``SaveImage`` transform. When specified,
                the ensemble prediction will save the prediction files, instead of keeping the files in the memory.
                Example: `{"_target_": "SaveImage", "output_dir": "./"}`
              - ``"sigmoid"``: use the sigmoid function (e.g. x > 0.5) to convert the prediction probability map
                to the label class prediction, otherwise argmax(x) is used.
              - ``"algo_spec_params"``: a dictionary to add pred_params that are specific to a model.
                The dict has a format of {"<name of algo>": "<pred_params for that algo>"}.
  
          The parameters in the second group is defined in the ``config`` of each Algo templates. Please check:
          https://github.com/Project-MONAI/research-contributions/tree/main/auto3dseg/algorithm_templates
  
  Returns:
      A list of tensors or file paths, depending on whether ``"image_save_func"`` is set.
code: def __call__(self, pred_param: dict | None = None) -> list:
      """
      Use the ensembled model to predict result.
  
      Args:
          pred_param: prediction parameter dictionary. The key has two groups: the first one will be consumed
              in this function, and the second group will be passed to the `InferClass` to override the
              parameters of the class functions.
              The first group contains:
  
                  - ``"infer_files"``: file paths to the images to read in a list.
                  - ``"files_slices"``: a value type of `slice`. The files_slices will slice the ``"infer_files"`` and
                    only make prediction on the infer_files[file_slices].
                  - ``"mode"``: ensemble mode. Currently "mean" and "vote" (majority voting) schemes are supported.
                  - ``"image_save_func"``: a dictionary used to instantiate the ``SaveImage`` transform. When specified,
                    the ensemble prediction will save the prediction files, instead of keeping the files in the memory.
                    Example: `{"_target_": "SaveImage", "output_dir": "./"}`
                  - ``"sigmoid"``: use the sigmoid function (e.g. x > 0.5) to convert the prediction probability map
                    to the label class prediction, otherwise argmax(x) is used.
                  - ``"algo_spec_params"``: a dictionary to add pred_params that are specific to a model.
                    The dict has a format of {"<name of algo>": "<pred_params for that algo>"}.
  
              The parameters in the second group is defined in the ``config`` of each Algo templates. Please check:
              https://github.com/Project-MONAI/research-contributions/tree/main/auto3dseg/algorithm_templates
  
      Returns:
          A list of tensors or file paths, depending on whether ``"image_save_func"`` is set.
      """
      param = {} if pred_param is None else deepcopy(pred_param)
      files = self.infer_files
  
      if "infer_files" in param:
          files = param.pop("infer_files")
  
      if "files_slices" in param:
          slices = param.pop("files_slices")
          files = files[slices]
  
      if "mode" in param:
          mode = param.pop("mode")
          self.mode = look_up_option(mode, supported=["mean", "vote"])
  
      sigmoid = param.pop("sigmoid", False)
  
      if "image_save_func" in param:
          img_saver = ConfigParser(
              param["image_save_func"]
          ).get_parsed_content()
  
      algo_spec_params = param.pop("algo_spec_params", {})
  
      outputs = []
      for _, file in (
          enumerate(tqdm(files, desc="Ensembling (rank 0)..."))
          if has_tqdm and pred_param and pred_param.get("rank", 0) == 0
          else enumerate(files)
      ):
          preds = []
          for algo in self.algo_ensemble:
              infer_algo_name = get_name_from_algo_id(algo[AlgoKeys.ID])
              infer_instance = algo[AlgoKeys.ALGO]
              _param = self._apply_algo_specific_param(
                  algo_spec_params, param, infer_algo_name
              )
              pred = infer_instance.predict(
                  predict_files=[file], predict_params=_param
              )
              preds.append(pred[0])
          if "image_save_func" in param:
              try:
                  ensemble_preds = self.ensemble_pred(
                      preds, sigmoid=sigmoid
                  )
              except BaseException:
                  ensemble_preds = self.ensemble_pred(
                      [_.to("cpu") for _ in preds], sigmoid=sigmoid
                  )
              res = img_saver(ensemble_preds)
              # res is the path to the saved results
              if hasattr(res, "meta") and "saved_to" in res.meta.keys():
                  res = res.meta["saved_to"]
              else:
                  warn("Image save path not returned.")
                  res = None
          else:
              warn(
                  "Prediction returned in list instead of disk, provide image_save_func to avoid out of memory."
              )
              res = self.ensemble_pred(preds, sigmoid=sigmoid)
          outputs.append(res)
      return outputs
  
imports: from __future__ import annotations
  import os
  from abc import ABC, abstractmethod
  from collections.abc import Mapping, Sequence
  from copy import deepcopy
  from typing import Any, cast
  from warnings import warn
  import numpy
  import torch
  import torch.distributed
  from monai.apps.auto3dseg.bundle_gen import BundleAlgo
  from monai.apps.auto3dseg.utils import get_name_from_algo_id, import_bundle_algo_history
  from monai.apps.utils import get_logger
  from monai.auto3dseg import concat_val_to_np
  from monai.auto3dseg.utils import _prepare_cmd_bcprun, _prepare_cmd_torchrun, _run_cmd_bcprun, _run_cmd_torchrun, datafold_read
  from monai.bundle import ConfigParser
  from monai.data import partition_dataset
  from monai.transforms import MeanEnsemble, SaveImage, VoteEnsemble
  from monai.utils import RankFilter
  from monai.utils.enums import AlgoKeys
  from monai.utils.misc import check_kwargs_exist_in_class_init, prob2class
  from monai.utils.module import look_up_option, optional_import
label_desc: Use image node_id 8 for calling the AlgoEnsemble obj's underlying member method code with example usage: obj.__call__(pred_param) and returns: outputs