code: def visualize_object_predictions(
      image: np.array,
      object_prediction_list,
      rect_th: int = None,
      text_size: float = None,
      text_th: float = None,
      color: tuple = None,
      hide_labels: bool = False,
      hide_conf: bool = False,
      output_dir: Optional[str] = None,
      file_name: str = "prediction_visual",
      export_format: str = "png",
  ):
      """
      Visualizes prediction category names, bounding boxes over the source image
      and exports it to output folder.
      Arguments:
          object_prediction_list: a list of prediction.ObjectPrediction
          rect_th: rectangle thickness
          text_size: size of the category name over box
          text_th: text thickness
          color: annotation color in the form: (0, 255, 0)
          hide_labels: hide labels
          hide_conf: hide confidence
          output_dir: directory for resulting visualization to be exported
          file_name: exported file will be saved as: output_dir+file_name+".png"
          export_format: can be specified as 'jpg' or 'png'
      """
      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
      for object_prediction in object_prediction_list:
          # deepcopy object_prediction_list so that original is not altered
          object_prediction = object_prediction.deepcopy()
          # visualize masks if present
          if object_prediction.mask is not None:
              # deepcopy mask so that original is not altered
              mask = object_prediction.mask.bool_mask
              # set color
              if colors is not None:
                  color = colors(object_prediction.category.id)
              # draw mask
              rgb_mask = apply_color_mask(mask, color)
              image = cv2.addWeighted(image, 1, rgb_mask, 0.6, 0)
  
      # add bboxes to image if present
      for object_prediction in object_prediction_list:
          # deepcopy object_prediction_list so that original is not altered
          object_prediction = object_prediction.deepcopy()
  
          bbox = object_prediction.bbox.to_xyxy()
          category_name = object_prediction.category.name
          score = object_prediction.score.value
  
          # set color
          if colors is not None:
              color = colors(object_prediction.category.id)
          # set bbox points
          p1, p2 = (int(bbox[0]), int(bbox[1])), (
              int(bbox[2]),
              int(bbox[3]),
          )
          # visualize boxes
          cv2.rectangle(
              image,
              p1,
              p2,
              color=color,
              thickness=rect_th,
          )
  
          if not hide_labels:
              # arange bounding box text location
              label = f"{category_name}"
  
              if not hide_conf:
                  label += f" {score:.2f}"
  
              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,
              )
  
      # export if output_dir is present
      if output_dir is not None:
          # export image with predictions
          Path(output_dir).mkdir(parents=True, exist_ok=True)
          # save inference result
          save_path = str(
              Path(output_dir) / (file_name + "." + export_format)
          )
          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 10 for calling a global function with example usage: visualize_object_predictions(image, object_prediction_list, rect_th, text_size, text_th, color, hide_labels, hide_conf, output_dir, file_name, export_format) and returns: dict