code: def get_roi_ap_from_df(inputs):
      """
      :param df: data frame.
      :param det_thresh: min_threshold for filtering out low confidence predictions.
      :param per_patient_ap: boolean flag. evaluate average precision per image and average over images,
      instead of computing one ap over data set.
      :return: average_precision (float)
      """
      df, det_thresh, per_patient_ap = inputs
  
      if per_patient_ap:
          pids_list = df.pid.unique()
          aps = []
          for match_iou in df.match_iou.unique():
              iou_df = df[df.match_iou == match_iou]
              for pid in pids_list:
                  pid_df = iou_df[iou_df.pid == pid]
                  all_p = len(pid_df[pid_df.class_label == 1])
                  pid_df = pid_df[
                      (pid_df.det_type == "det_fp")
                      | (pid_df.det_type == "det_tp")
                  ].sort_values("pred_score", ascending=False)
                  pid_df = pid_df[pid_df.pred_score > det_thresh]
                  if len(pid_df) == 0 and all_p == 0:
                      pass
                  elif len(pid_df) > 0 and all_p == 0:
                      aps.append(0)
                  else:
                      aps.append(compute_roi_ap(pid_df, all_p))
          return np.mean(aps)
  
      else:
          aps = []
          for match_iou in df.match_iou.unique():
              iou_df = df[df.match_iou == match_iou]
              all_p = len(iou_df[iou_df.class_label == 1])
              iou_df = iou_df[
                  (iou_df.det_type == "det_fp")
                  | (iou_df.det_type == "det_tp")
              ].sort_values("pred_score", ascending=False)
              iou_df = iou_df[iou_df.pred_score > det_thresh]
              if all_p > 0:
                  aps.append(compute_roi_ap(iou_df, all_p))
          return np.mean(aps)
  
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 1 for calling a global function with example usage: get_roi_ap_from_df(inputs) and returns: np, np