class_docstr: This provides Inference Engine for Monai Bundle.
code: def __init__(
      self,
      path: str,
      conf: Dict[str, str],
      const: Optional[BundleConstants] = None,
      type: Union[str, InferType] = "",
      pre_filter: Optional[Sequence] = None,
      post_filter: Optional[Sequence] = [SaveImaged],
      extend_load_image: bool = True,
      add_post_restore: bool = True,
      dropout: float = 0.0,
      load_strict=False,
      **kwargs,
  ):
      self.valid: bool = False
      self.const = const if const else BundleConstants()
  
      self.pre_filter = pre_filter
      self.post_filter = post_filter
      self.extend_load_image = extend_load_image
      self.dropout = dropout
  
      config_paths = [
          c
          for c in self.const.configs()
          if os.path.exists(os.path.join(path, "configs", c))
      ]
      if not config_paths:
          logger.warning(
              f"Ignore {path} as there is no infer config {self.const.configs()} exists"
          )
          return
  
      sys.path.insert(0, path)
      unload_module("scripts")
  
      self.bundle_path = path
      self.bundle_config_path = os.path.join(
          path, "configs", config_paths[0]
      )
      self.bundle_config = self._load_bundle_config(
          self.bundle_path, self.bundle_config_path
      )
      # For deepedit inferer - allow the use of clicks
      self.bundle_config.config["use_click"] = (
          True if type.lower() == "deepedit" else False
      )
  
      if self.dropout > 0:
          self.bundle_config["network_def"]["dropout"] = self.dropout
  
      network = None
      model_path = os.path.join(
          path, "models", self.const.model_pytorch()
      )
      if os.path.exists(model_path):
          network = self.bundle_config.get_parsed_content(
              self.const.key_network_def(), instantiate=True
          )
      else:
          model_path = os.path.join(
              path, "models", self.const.model_torchscript()
          )
          if not os.path.exists(model_path):
              logger.warning(
                  f"Ignore {path} as neither {self.const.model_pytorch()} nor {self.const.model_torchscript()} exists"
              )
              sys.path.remove(self.bundle_path)
              return
  
      # https://docs.monai.io/en/latest/mb_specification.html#metadata-json-file
      with open(
          os.path.join(path, "configs", self.const.metadata_json())
      ) as fp:
          metadata = json.load(fp)
  
      self.key_image, image = next(
          iter(metadata["network_data_format"]["inputs"].items())
      )
      self.key_pred, pred = next(
          iter(metadata["network_data_format"]["outputs"].items())
      )
  
      # labels = ({v.lower(): int(k) for k, v in pred.get("channel_def", {}).items() if v.lower() != "background"})
      labels = {}
      for k, v in pred.get("channel_def", {}).items():
          if (not type.lower() == "deepedit") and (
              v.lower() != "background"
          ):
              labels[v.lower()] = int(k)
          else:
              labels[v.lower()] = int(k)
      description = metadata.get("description")
      spatial_shape = image.get("spatial_shape")
      dimension = len(spatial_shape) if spatial_shape else 3
      type = self._get_type(os.path.basename(path), type)
  
      # if detection task, set post restore to False by default.
      self.add_post_restore = (
          False if type == "detection" else add_post_restore
      )
  
      super().__init__(
          path=model_path,
          network=network,
          type=type,
          labels=labels,
          dimension=dimension,
          description=description,
          preload=strtobool(conf.get("preload", "false")),
          load_strict=load_strict,
          **kwargs,
      )
  
      # Add models options if more than one model is provided by bundle.
      pytorch_models = [
          os.path.basename(p)
          for p in glob.glob(os.path.join(path, "models", "*.pt"))
      ]
      pytorch_models.sort(key=len)
      self._config.update({"model_filename": pytorch_models})
      # Add bundle's loadable params to MONAI Label config, load exposed keys and params to options panel
      for k in self.const.key_displayable_configs():
          if self.bundle_config.get(k):
              self.displayable_configs = self.bundle_config.get_parsed_content(k, instantiate=True)  # type: ignore
              self._config.update(self.displayable_configs)
  
      self.valid = True
      self.version = metadata.get("version")
      sys.path.remove(self.bundle_path)
  
imports: import glob
  import json
  import logging
  import os
  import sys
  from typing import Any, Callable, Dict, Optional, Sequence, Union
  from monai.bundle import ConfigItem, ConfigParser
  from monai.inferers import Inferer, SimpleInferer
  from monai.transforms import Compose, LoadImaged, SaveImaged
  from monailabel.interfaces.tasks.infer_v2 import InferType
  from monailabel.tasks.infer.basic_infer import BasicInferTask
  from monailabel.transform.post import Restored
  from monailabel.transform.pre import LoadImageTensord
  from monailabel.utils.others.class_utils import unload_module
  from monailabel.utils.others.generic import strtobool
label_desc: Use image node_id 1 to create a new BundleInferTask object from inherited base classes: BasicInferTask with example: obj = BundleInferTask(path, conf, const, type, pre_filter, post_filter, extend_load_image, add_post_restore, dropout, load_strict)