code: def ap_per_class(tp, conf, pred_cls, target_cls):
      """
      Computes the average precision, given the recall and precision curves.
      Method originally from https://github.com/rafaelpadilla/Object-Detection-Metrics.
  
      Args:
          tp (list): True positives.
          conf (list): Objectness value from 0-1.
          pred_cls (list): Predicted object classes.
          target_cls (list): Target object classes.
      """
      tp, conf, pred_cls, target_cls = (
          np.array(tp),
          np.array(conf),
          np.array(pred_cls),
          np.array(target_cls),
      )
  
      # Sort by objectness
      i = np.argsort(-conf)
      tp, conf, pred_cls = tp[i], conf[i], pred_cls[i]
  
      # Find unique classes
      unique_classes = np.unique(
          np.concatenate((pred_cls, target_cls), 0)
      )
  
      # Create Precision-Recall curve and compute AP for each class
      ap, p, r = [], [], []
      for c in unique_classes:
          i = pred_cls == c
          n_gt = sum(target_cls == c)  # Number of ground truth objects
          n_p = sum(i)  # Number of predicted objects
  
          if (n_p == 0) and (n_gt == 0):
              continue
          elif (n_p == 0) or (n_gt == 0):
              ap.append(0)
              r.append(0)
              p.append(0)
          else:
              # Accumulate FPs and TPs
              fpc = np.cumsum(1 - tp[i])
              tpc = np.cumsum(tp[i])
  
              # Recall
              recall_curve = tpc / (n_gt + 1e-16)
              r.append(tpc[-1] / (n_gt + 1e-16))
  
              # Precision
              precision_curve = tpc / (tpc + fpc)
              p.append(tpc[-1] / (tpc[-1] + fpc[-1]))
  
              # AP from recall-precision curve
              ap.append(compute_ap(recall_curve, precision_curve))
  
      return (
          np.array(ap),
          unique_classes.astype("int32"),
          np.array(r),
          np.array(p),
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import os
  import sys
  import numpy
  import itertools
  import paddle
  from ppdet.modeling.rbox_utils import poly2rbox_np
  from ppdet.utils.logger import setup_logger
label_desc: Use image node_id 6 for calling a global function with example usage: ap_per_class(tp, conf, pred_cls, target_cls) and returns: np,  unique_classes,  np,  np