code: def draw_bounding_boxes(
      image: torch.Tensor,
      boxes: torch.Tensor,
      labels: Optional[List[str]] = None,
      colors: 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: Optional[int] = None,
  ) -> 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 torch.jit.is_scripting() and not torch.jit.is_tracing():
          _log_api_usage_once(draw_bounding_boxes)
      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"
          )
      elif (boxes[:, 0] > boxes[:, 2]).any() or (
          boxes[:, 1] > boxes[:, 3]
      ).any():
          raise ValueError(
              "Boxes need to be in (xmin, ymin, xmax, ymax) format. Use torchvision.ops.box_convert to convert them"
          )
  
      num_boxes = boxes.shape[0]
  
      if num_boxes == 0:
          warnings.warn(
              "boxes doesn't contain any box. No box was drawn"
          )
          return image
  
      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."
          )
  
      colors = _parse_colors(colors, num_objects=num_boxes)
  
      if font is None:
          if font_size is not None:
              warnings.warn(
                  "Argument 'font_size' will be ignored since 'font' is not set."
              )
          txt_font = ImageFont.load_default()
      else:
          txt_font = ImageFont.truetype(font=font, size=font_size or 10)
  
      # 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)
  
      for bbox, color, label in zip(img_boxes, colors, labels):  # type: ignore[arg-type]
          if fill:
              fill_color = color + (100,)
              draw.rectangle(
                  bbox, width=width, outline=color, fill=fill_color
              )
          else:
              draw.rectangle(bbox, width=width, outline=color)
  
          if label is not None:
              margin = width + 1
              draw.text(
                  (bbox[0] + margin, bbox[1] + margin),
                  label,
                  fill=color,
                  font=txt_font,
              )
  
      return (
          torch.from_numpy(np.array(img_to_draw))
          .permute(2, 0, 1)
          .to(dtype=torch.uint8)
      )
  
imports: import collections
  import math
  import pathlib
  import warnings
  from itertools import repeat
  from types import FunctionType
  from typing import Any, BinaryIO, List, Optional, Tuple, Union
  import numpy
  import torch
  from PIL import Image, ImageColor, ImageDraw, ImageFont
label_desc: Use image node_id 3 for calling a global function with example usage: draw_bounding_boxes(image, boxes, labels, colors, fill, width, font, font_size) and returns: torch, image