code: def _matching_single_image_single_class(
      iou_fn: Callable[[np.ndarray, np.ndarray], np.ndarray],
      pred_boxes: np.ndarray,
      pred_scores: np.ndarray,
      gt_boxes: np.ndarray,
      gt_ignore: np.ndarray,
      max_detections: int,
      iou_thresholds: Sequence[float],
  ) -> dict[str, np.ndarray]:
      """
      Adapted from https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/cocoeval.py
  
      Args:
          iou_fn: compute overlap for each pair
          iou_thresholds: defined which IoU thresholds should be evaluated
          pred_boxes: predicted boxes from single batch; [D, dim * 2], D number
              of predictions
          pred_scores: predicted score for each bounding box; [D], D number of
              predictions
          gt_boxes: ground truth boxes; [G, dim * 2], G number of ground truth
          gt_ignore: specified if which ground truth boxes are not counted as
              true positives (detections which match theses boxes are not
              counted as false positives either); [G], G number of ground truth
          max_detections: maximum number of detections which should be evaluated
  
      Returns:
          dict: computed matching
  
          - `dtMatches`: matched detections [T, D], where T = number of
            thresholds, D = number of detections
          - `gtMatches`: matched ground truth boxes [T, G], where T = number
            of thresholds, G = number of ground truth
          - `dtScores`: prediction scores [D] detection scores
          - `gtIgnore`: ground truth boxes which should be ignored
            [G] indicate whether ground truth should be ignored
          - `dtIgnore`: detections which should be ignored [T, D],
            indicate which detections should be ignored
      """
      # filter for max_detections highest scoring predictions to speed up computation
      dt_ind = np.argsort(-pred_scores, kind="mergesort")
      dt_ind = dt_ind[:max_detections]
  
      pred_boxes = pred_boxes[dt_ind]
      pred_scores = pred_scores[dt_ind]
  
      # sort ignored ground truth to last positions
      gt_ind = np.argsort(gt_ignore, kind="mergesort")
      gt_boxes = gt_boxes[gt_ind]
      gt_ignore = gt_ignore[gt_ind]
  
      # ious between sorted(!) predictions and ground truth
      ious = iou_fn(
          pred_boxes, gt_boxes
      )  # array sized (num_preds, num_gts)
  
      num_preds, num_gts = ious.shape[0], ious.shape[1]
      gt_match = np.zeros((len(iou_thresholds), num_gts))
      dt_match = np.zeros((len(iou_thresholds), num_preds))
      dt_ignore = np.zeros((len(iou_thresholds), num_preds))
  
      for tind, t in enumerate(iou_thresholds):
          for dind, _d in enumerate(
              pred_boxes
          ):  # iterate detections starting from highest scoring one
              # information about best match so far (m=-1 -> unmatched)
              iou = min([t, 1 - 1e-10])
              m = -1
  
              for gind, _g in enumerate(
                  gt_boxes
              ):  # iterate ground truth
                  # if this gt already matched, continue
                  if gt_match[tind, gind] > 0:
                      continue
  
                  # if dt matched to reg gt, and on ignore gt, stop
                  if (
                      m > -1
                      and gt_ignore[m] == 0
                      and gt_ignore[gind] == 1
                  ):
                      break
  
                  # continue to next gt unless better match made
                  if ious[dind, gind] < iou:
                      continue
  
                  # if match successful and best so far, store appropriately
                  iou = ious[dind, gind]
                  m = gind
  
              # if match made, store id of match for both dt and gt
              if m == -1:
                  continue
              else:
                  dt_ignore[tind, dind] = int(gt_ignore[m])
                  dt_match[tind, dind] = 1
                  gt_match[tind, m] = 1
  
      # store results for given image and category
      return {
          "dtMatches": dt_match,  # [T, D], where T = number of thresholds, D = number of detections
          "gtMatches": gt_match,  # [T, G], where T = number of thresholds, G = number of ground truth
          "dtScores": pred_scores,  # [D] detection scores
          "gtIgnore": gt_ignore.reshape(
              -1
          ),  # [G] indicate whether ground truth should be ignored
          "dtIgnore": dt_ignore,  # [T, D], indicate which detections should be ignored
      }
  
imports: from __future__ import annotations
  from collections.abc import Callable, Sequence
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: _matching_single_image_single_class(iou_fn, pred_boxes, pred_scores, gt_boxes, gt_ignore, max_detections, iou_thresholds) and returns: dict