in detic/evaluation/oideval.py [0:0]
def accumulate(self):
"""Accumulate per image evaluation results and store the result in
self.eval.
"""
self.logger.info("Accumulating evaluation results.")
if not self.eval_imgs:
self.logger.warn("Please run evaluate first.")
if self.params.use_cats:
cat_ids = self.params.cat_ids
else:
cat_ids = [-1]
num_thrs = 1
num_recalls = 1
num_cats = len(cat_ids)
num_area_rngs = 1
num_imgs = len(self.params.img_ids)
# -1 for absent categories
precision = -np.ones(
(num_thrs, num_recalls, num_cats, num_area_rngs)
)
recall = -np.ones((num_thrs, num_cats, num_area_rngs))
# Initialize dt_pointers
dt_pointers = {}
for cat_idx in range(num_cats):
dt_pointers[cat_idx] = {}
for area_idx in range(num_area_rngs):
dt_pointers[cat_idx][area_idx] = {}
# Per category evaluation
for cat_idx in range(num_cats):
Nk = cat_idx * num_area_rngs * num_imgs
for area_idx in range(num_area_rngs):
Na = area_idx * num_imgs
E = [
self.eval_imgs[Nk + Na + img_idx]
for img_idx in range(num_imgs)
]
# Remove elements which are None
E = [e for e in E if not e is None]
if len(E) == 0:
continue
dt_scores = np.concatenate([e["dt_scores"] for e in E], axis=0)
dt_idx = np.argsort(-dt_scores, kind="mergesort")
dt_scores = dt_scores[dt_idx]
dt_m = np.concatenate([e["dt_matches"] for e in E], axis=1)[:, dt_idx]
dt_ig = np.concatenate([e["dt_ignore"] for e in E], axis=1)[:, dt_idx]
num_gt = sum([e['num_gt'] for e in E])
if num_gt == 0:
continue
tps = np.logical_and(dt_m, np.logical_not(dt_ig))
fps = np.logical_and(np.logical_not(dt_m), np.logical_not(dt_ig))
tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
dt_pointers[cat_idx][area_idx] = {
"tps": tps,
"fps": fps,
}
for iou_thr_idx, (tp, fp) in enumerate(zip(tp_sum, fp_sum)):
tp = np.array(tp)
fp = np.array(fp)
num_tp = len(tp)
rc = tp / num_gt
if num_tp:
recall[iou_thr_idx, cat_idx, area_idx] = rc[
-1
]
else:
recall[iou_thr_idx, cat_idx, area_idx] = 0
# np.spacing(1) ~= eps
pr = tp / (fp + tp + np.spacing(1))
pr = pr.tolist()
for i in range(num_tp - 1, 0, -1):
if pr[i] > pr[i - 1]:
pr[i - 1] = pr[i]
mAP = compute_average_precision(
np.array(pr, np.float).reshape(-1),
np.array(rc, np.float).reshape(-1))
precision[iou_thr_idx, :, cat_idx, area_idx] = mAP
self.eval = {
"params": self.params,
"counts": [num_thrs, num_recalls, num_cats, num_area_rngs],
"date": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"precision": precision,
"recall": recall,
"dt_pointers": dt_pointers,
}