# It's different from original nms because we have float coordinates on range [0; 1] :param dets: numpy array of boxes with shape: (N, 5). Order: x1, y1, x2, y2, score. All variables in range [0; 1] :param thresh: IoU value for boxes :return:
(dets, scores, thresh)
| 88 | |
| 89 | |
| 90 | def nms_float_fast(dets, scores, thresh): |
| 91 | """ |
| 92 | # It's different from original nms because we have float coordinates on range [0; 1] |
| 93 | :param dets: numpy array of boxes with shape: (N, 5). Order: x1, y1, x2, y2, score. All variables in range [0; 1] |
| 94 | :param thresh: IoU value for boxes |
| 95 | :return: |
| 96 | """ |
| 97 | x1 = dets[:, 0] |
| 98 | y1 = dets[:, 1] |
| 99 | x2 = dets[:, 2] |
| 100 | y2 = dets[:, 3] |
| 101 | |
| 102 | areas = (x2 - x1) * (y2 - y1) |
| 103 | order = scores.argsort()[::-1] |
| 104 | |
| 105 | keep = [] |
| 106 | while order.size > 0: |
| 107 | i = order[0] |
| 108 | keep.append(i) |
| 109 | xx1 = np.maximum(x1[i], x1[order[1:]]) |
| 110 | yy1 = np.maximum(y1[i], y1[order[1:]]) |
| 111 | xx2 = np.minimum(x2[i], x2[order[1:]]) |
| 112 | yy2 = np.minimum(y2[i], y2[order[1:]]) |
| 113 | |
| 114 | w = np.maximum(0.0, xx2 - xx1) |
| 115 | h = np.maximum(0.0, yy2 - yy1) |
| 116 | inter = w * h |
| 117 | ovr = inter / (areas[i] + areas[order[1:]] - inter) |
| 118 | inds = np.where(ovr <= thresh)[0] |
| 119 | order = order[inds + 1] |
| 120 | |
| 121 | return keep |
| 122 | |
| 123 | |
| 124 | def nms_method(boxes, scores, labels, method=3, iou_thr=0.5, sigma=0.5, thresh=0.001, weights=None): |