Runs greedy mAP evaluation, as done by pycocotools. Args: assemblies_gt: A dictionary mapping image ID (e.g. filepath) to ground truth assemblies. Should contain all the same keys as ``assemblies_pred``. assemblies_pred: A dictionary mapping image ID (e.g. filepath)
(
assemblies_gt: dict[Any, list[Assembly]],
assemblies_pred: dict[Any, list[Assembly]],
oks_sigma: float,
oks_thresholds: Iterable[float],
margin: int | float = 0,
symmetric_kpts: list[tuple[int, int]] | None = None,
)
| 1127 | |
| 1128 | |
| 1129 | def evaluate_assembly_greedy( |
| 1130 | assemblies_gt: dict[Any, list[Assembly]], |
| 1131 | assemblies_pred: dict[Any, list[Assembly]], |
| 1132 | oks_sigma: float, |
| 1133 | oks_thresholds: Iterable[float], |
| 1134 | margin: int | float = 0, |
| 1135 | symmetric_kpts: list[tuple[int, int]] | None = None, |
| 1136 | ) -> dict: |
| 1137 | """Runs greedy mAP evaluation, as done by pycocotools. |
| 1138 | |
| 1139 | Args: |
| 1140 | assemblies_gt: A dictionary mapping image ID (e.g. filepath) to ground truth |
| 1141 | assemblies. Should contain all the same keys as ``assemblies_pred``. |
| 1142 | assemblies_pred: A dictionary mapping image ID (e.g. filepath) to predicted |
| 1143 | assemblies. Should contain all the same keys as ``assemblies_gt``. |
| 1144 | oks_sigma: The sigma to use to compute OKS values for keypoints . |
| 1145 | oks_thresholds: The OKS thresholds at which to compute precision & recall. |
| 1146 | margin: The margin to use to compute bounding boxes from keypoints. |
| 1147 | symmetric_kpts: The symmetric keypoints in the dataset. |
| 1148 | """ |
| 1149 | recall_thresholds = np.linspace( # np.linspace(0, 1, 101) |
| 1150 | start=0.0, stop=1.00, num=int(np.round((1.00 - 0.0) / 0.01)) + 1, endpoint=True |
| 1151 | ) |
| 1152 | precisions = [] |
| 1153 | recalls = [] |
| 1154 | for oks_t in oks_thresholds: |
| 1155 | all_matched = [] |
| 1156 | total_gt_assemblies = 0 |
| 1157 | for ind, gt_assembly in assemblies_gt.items(): |
| 1158 | pred_assemblies = assemblies_pred.get(ind, []) |
| 1159 | num_gt_assemblies, matched = match_assemblies( |
| 1160 | pred_assemblies, |
| 1161 | gt_assembly, |
| 1162 | oks_sigma, |
| 1163 | margin, |
| 1164 | symmetric_kpts, |
| 1165 | greedy_matching=True, |
| 1166 | greedy_oks_threshold=oks_t, |
| 1167 | ) |
| 1168 | all_matched.extend(matched) |
| 1169 | total_gt_assemblies += num_gt_assemblies |
| 1170 | |
| 1171 | if len(all_matched) == 0: |
| 1172 | precisions.append(0.0) |
| 1173 | recalls.append(0.0) |
| 1174 | continue |
| 1175 | |
| 1176 | # Global sort of assemblies (across all images) by score |
| 1177 | scores = np.asarray([-m.score for m in all_matched]) |
| 1178 | sorted_pred_indices = np.argsort(scores, kind="mergesort") |
| 1179 | oks = np.asarray([match.oks for match in all_matched])[sorted_pred_indices] |
| 1180 | |
| 1181 | # Compute prediction and recall |
| 1182 | p, r = _compute_precision_and_recall(total_gt_assemblies, oks, oks_t, recall_thresholds) |
| 1183 | precisions.append(p) |
| 1184 | recalls.append(r) |
| 1185 | |
| 1186 | precisions = np.asarray(precisions) |
no test coverage detected