def compute(self):
    ap_by_classes = [0 for _ in range(self._n_classes)]
    for label in range(self._n_classes):
        num_annotations = self.num_annotations_by_classes[label]
        (tp_list, fp_list) = (np.array(self.tp_list_by_classes[label]), np.array(self.fp_list_by_classes[label]))
        scores = np.array(self.score_list_by_classes[label])
        indices = np.argsort((- scores))
        (tp_list, fp_list) = (tp_list[indices], fp_list[indices])
        (tp_list, fp_list) = (np.cumsum(tp_list), np.cumsum(fp_list))
        if (num_annotations == 0):
            ap_by_classes[label] = 0
            continue
        recall_curve = (tp_list / num_annotations)
        precision_curve = (tp_list / np.maximum((tp_list + fp_list), np.finfo(np.float64).eps))
        ap_by_classes[label] = self._compute_average_precision(recall_curve, precision_curve)
    return (ap_by_classes if self._by_classes else (sum(ap_by_classes) / len(ap_by_classes)))
def compute(self):
    ap_by_classes = [0 for _ in range(self._n_classes)]
    for label in range(self._n_classes):
        num_annotations = self.num_annotations_by_classes[label]
        (tp_list, fp_list) = (np.array(self.tp_list_by_classes[label]), np.array(self.fp_list_by_classes[label]))
        scores = np.array(self.score_list_by_classes[label])
        indices = np.argsort((- scores))
        (tp_list, fp_list) = (tp_list[indices], fp_list[indices])
        (tp_list, fp_list) = (np.cumsum(tp_list), np.cumsum(fp_list))
        if (num_annotations == 0):
            ap_by_classes[label] = 0
            continue
        recall_curve = (tp_list / num_annotations)
        precision_curve = (tp_list / np.maximum((tp_list + fp_list), np.finfo(np.float64).eps))
        ap_by_classes[label] = self._compute_average_precision(recall_curve, precision_curve)
    return (ap_by_classes if self._by_classes else (sum(ap_by_classes) / len(ap_by_classes)))