Computes the precision and recall scores at a given OKS threshold. Args: num_gt_assemblies: the number of ground truth assemblies (used to compute false negatives + true positives). oks_values: the OKS value to the matched GT assembly for each prediction oks_
(
num_gt_assemblies: int,
oks_values: np.ndarray,
oks_threshold: float,
recall_thresholds: np.ndarray,
)
| 1089 | |
| 1090 | |
| 1091 | def _compute_precision_and_recall( |
| 1092 | num_gt_assemblies: int, |
| 1093 | oks_values: np.ndarray, |
| 1094 | oks_threshold: float, |
| 1095 | recall_thresholds: np.ndarray, |
| 1096 | ) -> tuple[np.ndarray, np.ndarray]: |
| 1097 | """Computes the precision and recall scores at a given OKS threshold. |
| 1098 | |
| 1099 | Args: |
| 1100 | num_gt_assemblies: the number of ground truth assemblies (used to compute false |
| 1101 | negatives + true positives). |
| 1102 | oks_values: the OKS value to the matched GT assembly for each prediction |
| 1103 | oks_threshold: the OKS threshold at which recall and precision are being |
| 1104 | computed |
| 1105 | recall_thresholds: the recall thresholds to use to compute scores |
| 1106 | |
| 1107 | Returns: |
| 1108 | The precision and recall arrays at each recall threshold |
| 1109 | """ |
| 1110 | tp = np.cumsum(oks_values >= oks_threshold) |
| 1111 | fp = np.cumsum(oks_values < oks_threshold) |
| 1112 | rc = tp / num_gt_assemblies |
| 1113 | pr = tp / (fp + tp + np.spacing(1)) |
| 1114 | recall = rc[-1] |
| 1115 | |
| 1116 | # Guarantee precision decreases monotonically, see |
| 1117 | # https://jonathan-hui.medium.com/map-mean-average-precision-for-object-detection-45c121a31173 |
| 1118 | for i in range(len(pr) - 1, 0, -1): |
| 1119 | if pr[i] > pr[i - 1]: |
| 1120 | pr[i - 1] = pr[i] |
| 1121 | |
| 1122 | inds_rc = np.searchsorted(rc, recall_thresholds, side="left") |
| 1123 | precision = np.zeros(inds_rc.shape) |
| 1124 | valid = inds_rc < len(pr) |
| 1125 | precision[valid] = pr[inds_rc[valid]] |
| 1126 | return precision, recall |
| 1127 | |
| 1128 | |
| 1129 | def evaluate_assembly_greedy( |
no outgoing calls
no test coverage detected