code: def visualize_prediction(
      image: np.ndarray,
      boxes: List[List],
      classes: List[str],
      masks: Optional[List[np.ndarray]] = None,
      rect_th: float = None,
      text_size: float = None,
      text_th: float = None,
      color: tuple = None,
      hide_labels: bool = False,
      output_dir: Optional[str] = None,
      file_name: Optional[str] = "prediction_visual",
  ):
      """
      Visualizes prediction classes, bounding boxes over the source image
      and exports it to output folder.
      """
      elapsed_time = time.time()
      # deepcopy image so that original is not altered
      image = copy.deepcopy(image)
      # select predefined classwise color palette if not specified
      if color is None:
          colors = Colors()
      else:
          colors = None
      # set rect_th for boxes
      rect_th = rect_th or max(round(sum(image.shape) / 2 * 0.003), 2)
      # set text_th for category names
      text_th = text_th or max(rect_th - 1, 1)
      # set text_size for category names
      text_size = text_size or rect_th / 3
  
      # add masks to image if present
      if masks is not None:
          for mask in masks:
              # deepcopy mask so that original is not altered
              mask = copy.deepcopy(mask)
              # draw mask
              rgb_mask = apply_color_mask(np.squeeze(mask), color)
              image = cv2.addWeighted(image, 1, rgb_mask, 0.6, 0)
  
      # add bboxes to image if present
      for i in range(len(boxes)):
          # deepcopy boxso that original is not altered
          box = copy.deepcopy(boxes[i])
          class_ = classes[i]
  
          # set color
          if colors is not None:
              color = colors(class_)
          # set bbox points
          p1, p2 = (int(box[0]), int(box[1])), (
              int(box[2]),
              int(box[3]),
          )
          # visualize boxes
          cv2.rectangle(
              image,
              p1,
              p2,
              color=color,
              thickness=rect_th,
          )
  
          if not hide_labels:
              # arange bounding box text location
              label = f"{class_}"
              w, h = cv2.getTextSize(
                  label, 0, fontScale=text_size, thickness=text_th
              )[
                  0
              ]  # label width, height
              outside = p1[1] - h - 3 >= 0  # label fits outside box
              p2 = (
                  p1[0] + w,
                  p1[1] - h - 3 if outside else p1[1] + h + 3,
              )
              # add bounding box text
              cv2.rectangle(
                  image, p1, p2, color, -1, cv2.LINE_AA
              )  # filled
              cv2.putText(
                  image,
                  label,
                  (p1[0], p1[1] - 2 if outside else p1[1] + h + 2),
                  0,
                  text_size,
                  (255, 255, 255),
                  thickness=text_th,
              )
      if output_dir:
          # create output folder if not present
          Path(output_dir).mkdir(parents=True, exist_ok=True)
          # save inference result
          save_path = os.path.join(output_dir, file_name + ".png")
          cv2.imwrite(save_path, cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
  
      elapsed_time = time.time() - elapsed_time
      return {"image": image, "elapsed_time": elapsed_time}
  
imports: import copy
  import os
  import random
  import time
  from typing import List, Optional, Union
  import cv2
  import numpy
  import requests
  from PIL import Image
  from sahi.utils.file import Path
label_desc: Use image node_id 9 for calling a global function with example usage: visualize_prediction(image, boxes, classes, masks, rect_th, text_size, text_th, color, hide_labels, output_dir, file_name) and returns: dict