MCPcopy Create free account
hub / github.com/Kitware/COAT / eval_detection

Function eval_detection

eval_func.py:24–89  ·  view source on GitHub ↗

gallery_det (list of ndarray): n_det x [x1, y1, x2, y2, score] per image det_thresh (float): filter out gallery detections whose scores below this iou_thresh (float): treat as true positive if IoU is above this threshold labeled_only (bool): filter out unlabeled background people

(
    gallery_dataset, gallery_dets, det_thresh=0.5, iou_thresh=0.5, labeled_only=False
)

Source from the content-addressed store, hash-verified

22
23
24def eval_detection(
25 gallery_dataset, gallery_dets, det_thresh=0.5, iou_thresh=0.5, labeled_only=False
26):
27 """
28 gallery_det (list of ndarray): n_det x [x1, y1, x2, y2, score] per image
29 det_thresh (float): filter out gallery detections whose scores below this
30 iou_thresh (float): treat as true positive if IoU is above this threshold
31 labeled_only (bool): filter out unlabeled background people
32 """
33 assert len(gallery_dataset) == len(gallery_dets)
34 annos = gallery_dataset.annotations
35
36 y_true, y_score = [], []
37 count_gt, count_tp = 0, 0
38 for anno, det in zip(annos, gallery_dets):
39 gt_boxes = anno["boxes"]
40 if labeled_only:
41 # exclude the unlabeled people (pid == 5555)
42 inds = np.where(anno["pids"].ravel() != 5555)[0]
43 if len(inds) == 0:
44 continue
45 gt_boxes = gt_boxes[inds]
46 num_gt = gt_boxes.shape[0]
47
48 if det != []:
49 det = np.asarray(det)
50 inds = np.where(det[:, 4].ravel() >= det_thresh)[0]
51 det = det[inds]
52 num_det = det.shape[0]
53 else:
54 num_det = 0
55 if num_det == 0:
56 count_gt += num_gt
57 continue
58
59 ious = np.zeros((num_gt, num_det), dtype=np.float32)
60 for i in range(num_gt):
61 for j in range(num_det):
62 ious[i, j] = _compute_iou(gt_boxes[i], det[j, :4])
63 tfmat = ious >= iou_thresh
64 # for each det, keep only the largest iou of all the gt
65 for j in range(num_det):
66 largest_ind = np.argmax(ious[:, j])
67 for i in range(num_gt):
68 if i != largest_ind:
69 tfmat[i, j] = False
70 # for each gt, keep only the largest iou of all the det
71 for i in range(num_gt):
72 largest_ind = np.argmax(ious[i, :])
73 for j in range(num_det):
74 if j != largest_ind:
75 tfmat[i, j] = False
76 for j in range(num_det):
77 y_score.append(det[j, -1])
78 y_true.append(tfmat[:, j].any())
79 count_tp += tfmat.sum()
80 count_gt += num_gt
81

Callers 1

evaluate_performanceFunction · 0.90

Calls 2

_compute_iouFunction · 0.85
printFunction · 0.85

Tested by

no test coverage detected