class_docstr: Basic Inference Task Helper
class_docstr_tok: ["Basic","Inference","Task","Helper"]
docstr: Run Inferer over pre-processed Data.  Derive this logic to customize the normal behavior.
  In some cases, you want to implement your own for running chained inferers over pre-processed data
  
  :param data: pre-processed data
  :param convert_to_batch: convert input to batched input
  :param device: device type run load the model and run inferer
  :return: updated data with output_key stored that will be used for post-processing
code: def run_inferer(
      self, data: Dict[str, Any], convert_to_batch=True, device="cuda"
  ):
      """
      Run Inferer over pre-processed Data.  Derive this logic to customize the normal behavior.
      In some cases, you want to implement your own for running chained inferers over pre-processed data
  
      :param data: pre-processed data
      :param convert_to_batch: convert input to batched input
      :param device: device type run load the model and run inferer
      :return: updated data with output_key stored that will be used for post-processing
      """
  
      inferer = self.inferer(data)
      logger.info(
          f"Inferer:: {device} => {inferer.__class__.__name__} => {inferer.__dict__}"
      )
  
      network = self._get_network(device, data)
      if network:
          inputs = data[self.input_key]
          inputs = (
              inputs
              if torch.is_tensor(inputs)
              else torch.from_numpy(inputs)
          )
          inputs = inputs[None] if convert_to_batch else inputs
          inputs = inputs.to(torch.device(device))
  
          with torch.no_grad():
              outputs = inferer(inputs, network)
  
          if device.startswith("cuda"):
              torch.cuda.empty_cache()
  
          if convert_to_batch:
              if isinstance(outputs, dict):
                  outputs_d = decollate_batch(outputs)
                  outputs = outputs_d[0]
              else:
                  outputs = outputs[0]
  
          data[self.output_label_key] = outputs
      else:
          # consider them as callable transforms
          data = run_transforms(
              data, inferer, log_prefix="INF", log_name="Inferer"
          )
      return data
  
imports: import copy
  import logging
  import os
  import time
  from abc import abstractmethod
  from enum import Enum
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from monai.data import decollate_batch
  from monai.inferers import Inferer, SimpleInferer, SlidingWindowInferer
  from monai.utils import deprecated
  from monailabel.interfaces.exception import MONAILabelError, MONAILabelException
  from monailabel.interfaces.tasks.infer_v2 import InferTask, InferType
  from monailabel.interfaces.utils.transform import dump_data, run_transforms
  from monailabel.transform.cache import CacheTransformDatad
  from monailabel.transform.writer import ClassificationWriter, DetectionWriter, Writer
  from monailabel.utils.others.generic import device_list, device_map, name_to_device
label_desc: Use image node_id 18 for calling the BasicInferTask obj's underlying member method code with example usage: obj.run_inferer(data, convert_to_batch, device) and returns: data