MCPcopy
hub / github.com/msracver/Deformable-ConvNets / nms

Function nms

lib/nms/nms.py:31–68  ·  view source on GitHub ↗

greedily select boxes with high confidence and overlap with current maximum <= thresh rule out overlap >= thresh :param dets: [[x1, y1, x2, y2 score]] :param thresh: retain overlap < thresh :return: indexes to keep

(dets, thresh)

Source from the content-addressed store, hash-verified

29
30
31def nms(dets, thresh):
32 """
33 greedily select boxes with high confidence and overlap with current maximum <= thresh
34 rule out overlap >= thresh
35 :param dets: [[x1, y1, x2, y2 score]]
36 :param thresh: retain overlap < thresh
37 :return: indexes to keep
38 """
39 if dets.shape[0] == 0:
40 return []
41
42 x1 = dets[:, 0]
43 y1 = dets[:, 1]
44 x2 = dets[:, 2]
45 y2 = dets[:, 3]
46 scores = dets[:, 4]
47
48 areas = (x2 - x1 + 1) * (y2 - y1 + 1)
49 order = scores.argsort()[::-1]
50
51 keep = []
52 while order.size > 0:
53 i = order[0]
54 keep.append(i)
55 xx1 = np.maximum(x1[i], x1[order[1:]])
56 yy1 = np.maximum(y1[i], y1[order[1:]])
57 xx2 = np.minimum(x2[i], x2[order[1:]])
58 yy2 = np.minimum(y2[i], y2[order[1:]])
59
60 w = np.maximum(0.0, xx2 - xx1 + 1)
61 h = np.maximum(0.0, yy2 - yy1 + 1)
62 inter = w * h
63 ovr = inter / (areas[i] + areas[order[1:]] - inter)
64
65 inds = np.where(ovr <= thresh)[0]
66 order = order[inds + 1]
67
68 return keep
69
70
71def rescore(overlap, scores, thresh, type='gaussian'):

Callers 8

mainFunction · 0.90
pred_evalFunction · 0.90
forwardMethod · 0.90
pred_evalFunction · 0.90
forwardMethod · 0.90
pred_evalFunction · 0.90
forwardMethod · 0.90
_nmsFunction · 0.85

Calls

no outgoing calls

Tested by 3

pred_evalFunction · 0.72
pred_evalFunction · 0.72
pred_evalFunction · 0.72