code: def draw_bounding_boxes_and_labels(
      image: torch.Tensor,
      boxes: torch.Tensor,
      draw_boxes: bool,
      labels: Optional[List[str]] = None,
      label_color: Optional[
          Union[
              List[Union[str, Tuple[int, int, int]]],
              str,
              Tuple[int, int, int],
          ]
      ] = None,
      box_color: Optional[
          Union[
              List[Union[str, Tuple[int, int, int]]],
              str,
              Tuple[int, int, int],
          ]
      ] = None,
      fill: Optional[bool] = False,
      width: int = 1,
      font: Optional[str] = None,
      font_size: int = 10,
  ) -> torch.Tensor:
      """
      Draws bounding boxes on given image.
      The values of the input image should be uint8 between 0 and 255.
      If fill is True, Resulting Tensor should be saved as PNG image.
  
      Args:
          image (Tensor): Tensor of shape (C x H x W) and dtype uint8.
          boxes (Tensor): Tensor of size (N, 4) containing bounding boxes in (xmin, ymin, xmax, ymax) format. Note that
              the boxes are absolute coordinates with respect to the image. In other words: `0 <= xmin < xmax < W` and
              `0 <= ymin < ymax < H`.
          labels (List[str]): List containing the labels of bounding boxes.
          colors (color or list of colors, optional): List containing the colors
              of the boxes or single color for all boxes. The color can be represented as
              PIL strings e.g. "red" or "#FF00FF", or as RGB tuples e.g. ``(240, 10, 157)``.
              By default, random colors are generated for boxes.
          fill (bool): If `True` fills the bounding box with specified color.
          width (int): Width of bounding box.
          font (str): A filename containing a TrueType font. If the file is not found in this filename, the loader may
              also search in other directories, such as the `fonts/` directory on Windows or `/Library/Fonts/`,
              `/System/Library/Fonts/` and `~/Library/Fonts/` on macOS.
          font_size (int): The requested font size in points.
  
      Returns:
          img (Tensor[C, H, W]): Image Tensor of dtype uint8 with bounding boxes plotted.
      """
  
      if not isinstance(image, torch.Tensor):
          raise TypeError(f"Tensor expected, got {type(image)}")
      elif image.dtype != torch.uint8:
          raise ValueError(f"Tensor uint8 expected, got {image.dtype}")
      elif image.dim() != 3:
          raise ValueError("Pass individual images, not batches")
      elif image.size(0) not in {1, 3}:
          raise ValueError(
              "Only grayscale and RGB images are supported"
          )
  
      num_boxes = boxes.shape[0]
  
      if labels is None:
          labels: Union[List[str], List[None]] = [None] * num_boxes  # type: ignore[no-redef]
      elif len(labels) != num_boxes:
          raise ValueError(
              f"Number of boxes ({num_boxes}) and labels ({len(labels)}) mismatch. Please specify labels for each box."
          )
  
      # Handle Grayscale images
      if image.size(0) == 1:
          image = torch.tile(image, (3, 1, 1))
  
      ndarr = image.permute(1, 2, 0).cpu().numpy()
      img_to_draw = Image.fromarray(ndarr)
      img_boxes = boxes.to(torch.int64).tolist()
  
      if fill:
          draw = ImageDraw.Draw(img_to_draw, "RGBA")
      else:
          draw = ImageDraw.Draw(img_to_draw)
  
      txt_font = (
          ImageFont.load_default()
          if font is None
          else ImageFont.truetype(font=font, size=font_size)
      )
  
      for bbox, label in zip(img_boxes, labels):
          if draw_boxes:
              if fill:
                  fill_color = label_color + (100,)
                  draw.rectangle(
                      bbox,
                      width=width,
                      outline=label_color,
                      fill=fill_color,
                  )
              else:
                  draw.rectangle(bbox, width=width, outline=box_color)
  
          if label is not None:
              margin = width + 1
              draw.text(
                  (bbox[0] + margin, bbox[1] + margin),
                  label,
                  fill=label_color,
                  font=txt_font,
              )
  
      return (
          torch.from_numpy(np.array(img_to_draw))
          .permute(2, 0, 1)
          .to(dtype=torch.uint8)
      )
  
file_path: ImageAI/imageai/retinanet/utils.py
imports: from torchvision.io import ImageReadMode
  import torch
  from PIL import Image, ImageColor, ImageDraw, ImageFont
  from typing import List, Optional, Union, Tuple, BinaryIO
  import numpy
  import math
  import warnings
  import pathlib
label_desc: Use image node_id 6 for calling a global function with example usage: draw_bounding_boxes_and_labels(image, boxes, draw_boxes, labels, label_color, box_color, fill, width, font, font_size) and returns: torch