code: def _get_per_class_confusion_matrix_dict_(
      labels: List[Dict[str, Any]],
      predictions: List[np.ndarray],
      iou_threshold: Optional[float] = 0.5,
      num_procs: int = 1,
  ) -> DefaultDict[int, Dict[str, int]]:
      """
      Returns a confusion matrix dictionary for each class containing the number of True Positive, False Positive, and False Negative detections from the object detection model.
      """
      num_classes = len(predictions[0])
      num_images = len(predictions)
      pool = Pool(num_procs)
      counter_dict: DefaultDict[
          int, dict[str, int]
      ] = collections.defaultdict(lambda: {"TP": 0, "FP": 0, "FN": 0})
  
      for class_num in range(num_classes):
          pred_bboxes, lab_bboxes = _filter_by_class(
              labels, predictions, class_num
          )
          tpfpfn = pool.starmap(
              _calculate_true_positives_false_positives,
              zip(
                  pred_bboxes,
                  lab_bboxes,
                  [iou_threshold for _ in range(num_images)],
                  [True for _ in range(num_images)],
              ),
          )
  
          for image_idx, (tp, fp, fn) in enumerate(tpfpfn):  # type: ignore
              counter_dict[class_num]["TP"] += np.sum(tp)
              counter_dict[class_num]["FP"] += np.sum(fp)
              counter_dict[class_num]["FN"] += np.sum(fn)
  
      return counter_dict
  
imports: from multiprocessing import Pool
  from typing import Optional, Any, Dict, Tuple, Union, List, TYPE_CHECKING, TypeVar, DefaultDict
  import numpy
  import collections
  from cleanlab.internal.constants import MAX_CLASS_TO_SHOW, ALPHA, EPSILON, TINY_VALUE
  from cleanlab.object_detection.filter import _filter_by_class, _calculate_true_positives_false_positives
  from cleanlab.object_detection.rank import _get_valid_inputs_for_compute_scores, _separate_prediction, _separate_label, _get_prediction_type
  from cleanlab.internal.object_detection_utils import bbox_xyxy_to_xywh
label_desc: Use image node_id 8 for calling a global function with example usage: _get_per_class_confusion_matrix_dict_(labels, predictions, iou_threshold, num_procs) and returns: counter_dict