code: def compute_roi_ap(df, all_p):
      """
      adapted from: https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/cocoeval.py
      :param df: dataframe containing class labels of predictions sorted in descending manner by their prediction score.
      :param all_p: number of all ground truth objects. (for denominator of recall.)
      :return:
      """
      tp = df.class_label.values
      fp = (tp == 0) * 1
      # recall thresholds, where precision will be measured
      R = np.linspace(0.0, 1, 101, endpoint=True)
      tp_sum = np.cumsum(tp)
      fp_sum = np.cumsum(fp)
      nd = len(tp)
      rc = tp_sum / all_p
      pr = tp_sum / (fp_sum + tp_sum)
      # initialize precision array over recall steps.
      q = np.zeros((len(R),))
  
      # numpy is slow without cython optimization for accessing elements
      # use python array gets significant speed improvement
      pr = pr.tolist()
      q = q.tolist()
      for i in range(nd - 1, 0, -1):
          if pr[i] > pr[i - 1]:
              pr[i - 1] = pr[i]
  
      # discretize empiric recall steps with given bins.
      inds = np.searchsorted(rc, R, side="left")
      try:
          for ri, pi in enumerate(inds):
              q[ri] = pr[pi]
      except:
          pass
  
      return np.mean(q)
  
file_path: medicaldetectiontoolkit/evaluator.py
imports: import os
  import numpy
  import pandas
  from sklearn.metrics import roc_auc_score, average_precision_score
  from sklearn.metrics import roc_curve, precision_recall_curve
  import utils.model_utils
  import plotting
  from multiprocessing import Pool
label_desc: Use image node_id 2 for calling a global function with example usage: compute_roi_ap(df, all_p) and returns: np