code: def calculate_per_class_metrics(
      labels: List[Dict[str, Any]],
      predictions: List[np.ndarray],
      num_procs: int = 1,
      class_names=None,
  ) -> Dict[Union[int, str], Dict[str, float]]:
      """
      Calculate the object detection model's precision, recall, and F1 score for each class in the dataset.
  
      These metrics can help you identify model strengths and weaknesses, and provide reference statistics for model evaluation and comparisons.
  
      Parameters
      ----------
      labels:
          A list of ``N`` dictionaries such that ``labels[i]`` contains the given labels for the `i`-th image.
          Refer to documentation for this argument in :py:func:`object_detection.filter.find_label_issues <cleanlab.object_detection.filter.find_label_issues>` for further details.
  
      predictions:
          A list of ``N`` ``np.ndarray`` such that ``predictions[i]`` corresponds to the model predictions for the `i`-th image.
          Refer to documentation for this argument in :py:func:`object_detection.filter.find_label_issues <cleanlab.object_detection.filter.find_label_issues>` for further details.
  
      num_procs:
          Number of processes for parallelization. Default is 1.
  
      class_names:
          Optional dictionary mapping one-hot-encoded class labels back to their original class names in the format ``{"integer-label": "original-class-name"}``
  
  
      Returns
      -------
      per_class_metrics: dict
          A dictionary containing per-class metrics computed from the object detection model's average confusion matrix values across a range of Intersection over Union thresholds.
  
          The default range of Intersection over Union thresholds is from 0.5 to 0.95 with a step size of 0.05.
      """
      avg_metrics = get_average_per_class_confusion_matrix(
          labels, predictions, num_procs, class_names=class_names
      )
  
      avg_metrics_dict = {}
      for class_name in avg_metrics:
          tp = avg_metrics[class_name]["TP"]
          fp = avg_metrics[class_name]["FP"]
          fn = avg_metrics[class_name]["FN"]
  
          precision = tp / (
              tp + fp + TINY_VALUE
          )  # Avoid division by zero
          recall = tp / (tp + fn + TINY_VALUE)  # Avoid division by zero
          f1 = (
              2
              * (precision * recall)
              / (precision + recall + TINY_VALUE)
          )  # Avoid division by zero
  
          avg_metrics_dict[class_name] = {
              "average precision": precision,
              "average recall": recall,
              "average f1": f1,
          }
  
      return avg_metrics_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 11 for calling a global function with example usage: calculate_per_class_metrics(labels, predictions, num_procs, class_names) and returns: avg_metrics_dict