Greedily select boxes with high confidence and overlap <= thr. Args: dets: [[x1, y1, x2, y2, score]]. thr: Retain overlap < thr. Returns: list: Indexes to keep.
(dets, thr)
| 7 | |
| 8 | |
| 9 | def nms(dets, thr): |
| 10 | """Greedily select boxes with high confidence and overlap <= thr. |
| 11 | |
| 12 | Args: |
| 13 | dets: [[x1, y1, x2, y2, score]]. |
| 14 | thr: Retain overlap < thr. |
| 15 | |
| 16 | Returns: |
| 17 | list: Indexes to keep. |
| 18 | """ |
| 19 | if len(dets) == 0: |
| 20 | return [] |
| 21 | |
| 22 | x1 = dets[:, 0] |
| 23 | y1 = dets[:, 1] |
| 24 | x2 = dets[:, 2] |
| 25 | y2 = dets[:, 3] |
| 26 | scores = dets[:, 4] |
| 27 | |
| 28 | areas = (x2 - x1 + 1) * (y2 - y1 + 1) |
| 29 | order = scores.argsort()[::-1] |
| 30 | |
| 31 | keep = [] |
| 32 | while len(order) > 0: |
| 33 | i = order[0] |
| 34 | keep.append(i) |
| 35 | xx1 = np.maximum(x1[i], x1[order[1:]]) |
| 36 | yy1 = np.maximum(y1[i], y1[order[1:]]) |
| 37 | xx2 = np.minimum(x2[i], x2[order[1:]]) |
| 38 | yy2 = np.minimum(y2[i], y2[order[1:]]) |
| 39 | |
| 40 | w = np.maximum(0.0, xx2 - xx1 + 1) |
| 41 | h = np.maximum(0.0, yy2 - yy1 + 1) |
| 42 | inter = w * h |
| 43 | ovr = inter / (areas[i] + areas[order[1:]] - inter) |
| 44 | |
| 45 | inds = np.where(ovr <= thr)[0] |
| 46 | order = order[inds + 1] |
| 47 | |
| 48 | return keep |
| 49 | |
| 50 | |
| 51 | def oks_iou(g, d, a_g, a_d, sigmas=None, vis_thr=None): |