code: def non_maximum_suppression(
      preds: Dict[str, np.ndarray],
      iou_threshold: float,
      confidence_threshold: Optional[float] = None,
  ) -> Dict[str, np.ndarray]:
      """
      Perform non-maximum suppression on the predicted object detection labels of a single image.
  
      :param preds: Predicted labels of format `Dict[str, np.ndarray]` for a single image. The fields of the Dict are
                    as follows:
  
                    - boxes [N, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
                    - labels [N]: the labels for each image.
                    - scores [N]: the scores of each prediction.
      :param iou_threshold: The IoU threshold to discard overlapping bounding boxes.
      :param confidence_threshold: The confidence threshold to discard bounding boxes.
      return: Filtered predicted labels of the single image in the same format as the input.
      """
      boxes = preds["boxes"]
      labels = preds["labels"]
      scores = preds["scores"]
  
      # Filter out bounding boxes below confidence threshold
      if confidence_threshold is not None:
          mask = scores >= confidence_threshold
          boxes = boxes[mask]
          labels = labels[mask]
          scores = scores[mask]
  
      # Candidate bounding boxes
      keep_indices = []
      indices = np.argsort(scores)[::-1]
  
      while len(indices) > 0:
          # Get first bounding box
          current_idx = indices[0]
          box_1 = boxes[current_idx]
          label_1 = labels[current_idx]
  
          keep_indices.append(current_idx)
          remove_indices = [0]
  
          # Find overlapping bounding boxes above IoU threshold
          for i, idx in enumerate(indices[1:], start=1):
              box_2 = boxes[idx]
              label_2 = labels[idx]
  
              if label_1 != label_2:
                  continue
  
              iou = intersection_over_union(box_1, box_2)
              if iou >= iou_threshold:
                  remove_indices.append(i)
  
          # Remove overlapping bounding boxes from candidates
          indices = np.delete(indices, remove_indices)
  
      filtered_preds = {
          "boxes": boxes[keep_indices],
          "labels": labels[keep_indices],
          "scores": scores[keep_indices],
      }
      return filtered_preds
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import math
  import os
  import shutil
  import sys
  import tarfile
  import warnings
  import zipfile
  from functools import wraps
  from inspect import signature
  from typing import TYPE_CHECKING, Callable, List, Dict, Optional, Tuple, Union
  import numpy
  import six
  from scipy.special import gammainc
  from tqdm.auto import tqdm
  from art import config
label_desc: Use image node_id 27 for calling a global function with example usage: non_maximum_suppression(preds, iou_threshold, confidence_threshold) and returns: filtered_preds