code: def _voc_computePrecisionRecallAp(
      class_recs,
      confidence,
      image_ids,
      BB,
      ovthresh=0.5,
      use_07_metric=False,
  ):
      """
      Computes precision, recall. and average precision
      """
      if len(BB) == 0:
          return 0.0, 0.0, 0.0
  
      # sort by confidence
      sorted_ind = np.argsort(-confidence)
  
      BB = BB[sorted_ind, :]
      image_ids = [image_ids[x] for x in sorted_ind]
  
      # go down dets and mark TPs and FPs
      nd = len(image_ids)
      tp = np.zeros(nd)
      fp = np.zeros(nd)
      for d in range(nd):
          R = class_recs[image_ids[d]]
          bb = BB[d, :].astype(float)
          ovmax = -np.inf
          BBGT = R["bbox"].astype(float)
  
          if BBGT.size > 0:
              # compute overlaps
              ixmin = np.maximum(BBGT[:, 0], bb[0])
              iymin = np.maximum(BBGT[:, 1], bb[1])
              ixmax = np.minimum(BBGT[:, 2], bb[2])
              iymax = np.minimum(BBGT[:, 3], bb[3])
              iw = np.maximum(ixmax - ixmin + 1.0, 0.0)
              ih = np.maximum(iymax - iymin + 1.0, 0.0)
              inters = iw * ih
  
              # union
              uni = (
                  (bb[2] - bb[0] + 1.0) * (bb[3] - bb[1] + 1.0)
                  + (BBGT[:, 2] - BBGT[:, 0] + 1.0)
                  * (BBGT[:, 3] - BBGT[:, 1] + 1.0)
                  - inters
              )
  
              overlaps = inters / uni
              ovmax = np.max(overlaps)
              jmax = np.argmax(overlaps)
  
          if ovmax > ovthresh:
              if not R["difficult"][jmax]:
                  if not R["det"][jmax]:
                      tp[d] = 1.0
                      R["det"][jmax] = 1
                  else:
                      fp[d] = 1.0
          else:
              fp[d] = 1.0
  
      # compute precision recall
      npos = sum([len(cr["bbox"]) for cr in class_recs])
      fp = np.cumsum(fp)
      tp = np.cumsum(tp)
      rec = tp / float(npos)
      # avoid divide by zero in case the first detection matches a difficult ground truth
      prec = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
      ap = computeAveragePrecision(rec, prec, use_07_metric)
      return rec, prec, ap
  
imports: import numpy
  from utils.nms_wrapper import apply_nms_to_test_set_results
label_desc: Use image node_id 4 for calling a global function with example usage: _voc_computePrecisionRecallAp(class_recs, confidence, image_ids, BB, ovthresh, use_07_metric) and returns: rec,  prec,  ap, int,  int,  int