class_docstr: A predictor that runs the model asynchronously, possibly on >1 GPUs.
  Because rendering the visualization takes considerably amount of time,
  this helps improve throughput when rendering videos.
class_docstr_tok: ["A","predictor","that","runs","the","model","asynchronously",",","possibly","on",">","1","GPUs",".","Because","rendering","the","visualization","takes","considerably","amount","of","time",",","this","helps","improve","throughput","when","rendering","videos","."]
docstr: Args:
      cfg (CfgNode):
      num_gpus (int): if 0, will run on CPU
docstr_tok: ["Args",":","cfg","(","CfgNode",")",":","num_gpus","(","int",")",":","if","0",",","will","run","on","CPU"]
code: def __init__(self, cfg, num_gpus: int = 1):
      """
      Args:
          cfg (CfgNode):
          num_gpus (int): if 0, will run on CPU
      """
      num_workers = max(num_gpus, 1)
      self.task_queue = mp.Queue(maxsize=num_workers * 3)
      self.result_queue = mp.Queue(maxsize=num_workers * 3)
      self.procs = []
      for gpuid in range(max(num_gpus, 1)):
          cfg = cfg.clone()
          cfg.defrost()
          cfg.MODEL.DEVICE = (
              "cuda:{}".format(gpuid) if num_gpus > 0 else "cpu"
          )
          self.procs.append(
              AsyncPredictor._PredictWorker(
                  cfg, self.task_queue, self.result_queue
              )
          )
  
      self.put_idx = 0
      self.get_idx = 0
      self.result_rank = []
      self.result_data = []
  
      for p in self.procs:
          p.start()
      atexit.register(self.shutdown)
  
imports: import atexit
  import bisect
  import multiprocessing
  from collections import deque
  import cv2
  import torch
  from detectron2.data import MetadataCatalog
  from detectron2.engine.defaults import DefaultPredictor
  from detectron2.utils.video_visualizer import VideoVisualizer
  from detectron2.utils.visualizer import ColorMode, Visualizer
label_desc: Use image node_id 1 to create a new AsyncPredictor object  with example: obj = AsyncPredictor(cfg, num_gpus)