code: def _compute_matches(
      cats, pred_ious, iou_thresh, eval_key, id_key, iou_key
  ):
      matches = []
  
      # Match preds to GT, highest confidence first
      for cat, segments in cats.items():
          gt_map = {gt.id: gt for gt in segments["gts"]}
  
          # Match each prediction to the highest available IoU ground truth
          for pred in segments["preds"]:
              if pred.id in pred_ious:
                  best_match = None
                  best_match_iou = iou_thresh
                  for gt_id, iou in pred_ious[pred.id]:
                      gt = gt_map[gt_id]
  
                      # Each gt can only match with one prediction
                      if gt[id_key] != _NO_MATCH_ID:
                          continue
  
                      if iou < best_match_iou:
                          continue
  
                      best_match_iou = iou
                      best_match = gt_id
  
                  if best_match:
                      gt = gt_map[best_match]
  
                      gt[eval_key] = (
                          "tp" if gt.label == pred.label else "fn"
                      )
                      gt[id_key] = pred.id
                      gt[iou_key] = best_match_iou
  
                      pred[eval_key] = (
                          "tp" if gt.label == pred.label else "fp"
                      )
                      pred[id_key] = best_match
                      pred[iou_key] = best_match_iou
  
                      matches.append(
                          (
                              gt.label,
                              pred.label,
                              best_match_iou,
                              pred.confidence,
                              gt.id,
                              pred.id,
                          )
                      )
                  else:
                      pred[eval_key] = "fp"
                      matches.append(
                          (
                              None,
                              pred.label,
                              None,
                              pred.confidence,
                              None,
                              pred.id,
                          )
                      )
  
              elif pred.label == cat:
                  pred[eval_key] = "fp"
                  matches.append(
                      (
                          None,
                          pred.label,
                          None,
                          pred.confidence,
                          None,
                          pred.id,
                      )
                  )
  
          # Leftover GTs are false negatives
          for gt in segments["gts"]:
              if gt[id_key] == _NO_MATCH_ID:
                  gt[eval_key] = "fn"
                  matches.append(
                      (gt.label, None, None, None, gt.id, None)
                  )
  
      return matches
  
imports: import logging
  from collections import defaultdict
  import numpy
  import eta.core.utils
  import fiftyone.core.plots
  import fiftyone.utils.iou
  from .detection import DetectionEvaluation, DetectionEvaluationConfig, DetectionResults
label_desc: Use image node_id 4 for calling a global function with example usage: _compute_matches(cats, pred_ious, iou_thresh, eval_key, id_key, iou_key) and returns: matches