docstr: Draw labels and bouding boxes for one image. By default, predicted
  labels are drawn in the top left corner of the image or corresponding
  bounding boxes. For ground truth labels (setting True for ground_truth flag),
  labels will be drawn in the bottom left corner.
  Args:
      frame (array-like): a tensor or numpy array of shape (H, W, C),
      where H and W correspond to
          the height and width of the image respectively. C is the number of
          color channels. The image is required to be in RGB format since that
          is a requirement of the Matplotlib library. The image is also expected
          to be in the range [0, 255].
      preds (tensor or list): If ground_truth is False, provide a float tensor of
          shape (num_boxes, num_classes) that contains all of the confidence
          scores of the model. For recognition task, input shape can be (num_classes,).
          To plot true label (ground_truth is True), preds is a list contains int32
          of the shape (num_boxes, true_class_ids) or (true_class_ids,).
      bboxes (Optional[tensor]): shape (num_boxes, 4) that contains the coordinates
          of the bounding boxes.
      alpha (Optional[float]): transparency level of the bounding boxes.
      text_alpha (Optional[float]): transparency level of the box wrapped around
          text labels.
      ground_truth (bool): whether the prodived bounding boxes are ground-truth.
  Returns:
      An image with bounding box annotations and corresponding bbox
      labels plotted on it.
docstr_tok: ["Draw","labels","and","bouding","boxes","for","one","image",".","By","default",",","predicted","labels","are","drawn","in","the","top","left","corner","of","the","image","or","corresponding","bounding","boxes",".","For","ground","truth","labels","(","setting","True","for","ground_truth","flag",")",",","labels","will","be","drawn","in","the","bottom","left","corner",".","Args",":","frame","(","array-like",")",":","a","tensor","or","numpy","array","of","shape","(","H",",","W",",","C",")",",","where","H","and","W","correspond","to","the","height","and","width","of","the","image","respectively",".","C","is","the","number","of","color","channels",".","The","image","is","required","to","be","in","RGB","format","since","that","is","a","requirement","of","the","Matplotlib","library",".","The","image","is","also","expected","to","be","in","the","range","[","0",",","255","]",".","preds","(","tensor","or","list",")",":","If","ground_truth","is","False",",","provide","a","float","tensor","of","shape","(","num_boxes",",","num_classes",")","that","contains","all","of","the","confidence","scores","of","the","model",".","For","recognition","task",",","input","shape","can","be","(","num_classes",",",")",".","To","plot","true","label","(","ground_truth","is","True",")",",","preds","is","a","list","contains","int32","of","the","shape","(","num_boxes",",","true_class_ids",")","or","(","true_class_ids",",",")",".","bboxes","(","Optional","[","tensor","]",")",":","shape","(","num_boxes",",","4",")","that","contains","the","coordinates","of","the","bounding","boxes",".","alpha","(","Optional","[","float","]",")",":","transparency","level","of","the","bounding","boxes",".","text_alpha","(","Optional","[","float","]",")",":","transparency","level","of","the","box","wrapped","around","text","labels",".","ground_truth","(","bool",")",":","whether","the","prodived","bounding","boxes","are","ground-truth",".","Returns",":","An","image","with","bounding","box","annotations","and","corresponding","bbox","labels","plotted","on","it","."]
code: def draw_one_frame(
      self,
      frame: Union[torch.Tensor, np.ndarray],
      preds: Union[torch.Tensor, List[float]],
      bboxes: Optional[torch.Tensor] = None,
      alpha: float = 0.5,
      text_alpha: float = 0.7,
      ground_truth: bool = False,
  ) -> np.ndarray:
      """
      Draw labels and bouding boxes for one image. By default, predicted
      labels are drawn in the top left corner of the image or corresponding
      bounding boxes. For ground truth labels (setting True for ground_truth flag),
      labels will be drawn in the bottom left corner.
      Args:
          frame (array-like): a tensor or numpy array of shape (H, W, C),
          where H and W correspond to
              the height and width of the image respectively. C is the number of
              color channels. The image is required to be in RGB format since that
              is a requirement of the Matplotlib library. The image is also expected
              to be in the range [0, 255].
          preds (tensor or list): If ground_truth is False, provide a float tensor of
              shape (num_boxes, num_classes) that contains all of the confidence
              scores of the model. For recognition task, input shape can be (num_classes,).
              To plot true label (ground_truth is True), preds is a list contains int32
              of the shape (num_boxes, true_class_ids) or (true_class_ids,).
          bboxes (Optional[tensor]): shape (num_boxes, 4) that contains the coordinates
              of the bounding boxes.
          alpha (Optional[float]): transparency level of the bounding boxes.
          text_alpha (Optional[float]): transparency level of the box wrapped around
              text labels.
          ground_truth (bool): whether the prodived bounding boxes are ground-truth.
      Returns:
          An image with bounding box annotations and corresponding bbox
          labels plotted on it.
      """
      if isinstance(preds, torch.Tensor):
          if preds.ndim == 1:
              preds = preds.unsqueeze(0)
          n_instances = preds.shape[0]
      elif isinstance(preds, list):
          n_instances = len(preds)
      else:
          logger.error("Unsupported type of prediction input.")
          return
  
      if ground_truth:
          top_scores, top_classes = [None] * n_instances, preds
  
      elif self.mode == "top-k":
          top_scores, top_classes = torch.topk(preds, k=self.top_k)
          top_scores, top_classes = (
              top_scores.tolist(),
              top_classes.tolist(),
          )
      elif self.mode == "thres":
          top_scores, top_classes = [], []
          for pred in preds:
              mask = pred >= self.thres
              top_scores.append(pred[mask].tolist())
              top_class = torch.squeeze(
                  torch.nonzero(mask), dim=-1
              ).tolist()
              top_classes.append(top_class)
  
      # Create labels top k predicted classes with their scores.
      text_labels = []
      for i in range(n_instances):
          text_labels.append(
              _create_text_labels(
                  top_classes[i],
                  top_scores[i],
                  self.class_names,
                  ground_truth=ground_truth,
              )
          )
      frame_visualizer = ImgVisualizer(frame, meta=None)
      font_size = min(
          max(np.sqrt(frame.shape[0] * frame.shape[1]) // 25, 5), 9
      )
      top_corner = not ground_truth
      if bboxes is not None:
          assert len(preds) == len(
              bboxes
          ), "Encounter {} predictions and {} bounding boxes".format(
              len(preds), len(bboxes)
          )
          for i, box in enumerate(bboxes):
              text = text_labels[i]
              pred_class = top_classes[i]
              colors = [self._get_color(pred) for pred in pred_class]
  
              box_color = "r" if ground_truth else "g"
              line_style = "--" if ground_truth else "-."
              frame_visualizer.draw_box(
                  box,
                  alpha=alpha,
                  edge_color=box_color,
                  line_style=line_style,
              )
              frame_visualizer.draw_multiple_text(
                  text,
                  box,
                  top_corner=top_corner,
                  font_size=font_size,
                  box_facecolors=colors,
                  alpha=text_alpha,
              )
      else:
          text = text_labels[0]
          pred_class = top_classes[0]
          colors = [self._get_color(pred) for pred in pred_class]
          frame_visualizer.draw_multiple_text(
              text,
              torch.Tensor([0, 5, frame.shape[1], frame.shape[0] - 5]),
              top_corner=top_corner,
              font_size=font_size,
              box_facecolors=colors,
              alpha=text_alpha,
          )
  
      return frame_visualizer.output.get_image()
  
imports: from __future__ import annotations
  import itertools
  import logging
  from types import SimpleNamespace
  from typing import Dict, List, Optional, Tuple, Union
  import matplotlib.pyplot
  import numpy
  import torch
  from detectron2.utils.visualizer import Visualizer
label_desc: Use image node_id 3 for calling the VideoVisualizer obj's underlying member method code with example usage: obj.draw_one_frame(frame, preds, bboxes, alpha, text_alpha, ground_truth) and returns: frame_visualizer