(boxes, scores, iou_threshold=0.3)
| 170 | |
| 171 | |
| 172 | def nms(boxes, scores, iou_threshold=0.3): |
| 173 | if 0 == len(boxes): |
| 174 | return [] |
| 175 | rects = list(boxes) |
| 176 | for i in range(len(rects)): |
| 177 | rects[i] = list(rects[i]) |
| 178 | rects[i].append(scores[i]) |
| 179 | rects[i].append(i) |
| 180 | rects.sort(key=lambda x: x[1]) |
| 181 | idx = 0 |
| 182 | for i in range(len(rects)): |
| 183 | if is_overlap_v2(rects[i], rects[idx], iou_threshold): |
| 184 | rects[idx] = simple_merge(rects[idx], rects[i]) |
| 185 | else: |
| 186 | idx += 1 |
| 187 | if idx != i: |
| 188 | rects[idx] = rects[i] |
| 189 | rects = rects[:idx + 1] |
| 190 | rects.sort(key=lambda x: x[0]) |
| 191 | idx = 0 |
| 192 | for i in range(len(rects)): |
| 193 | if is_overlap_v2(rects[i], rects[idx], iou_threshold): |
| 194 | rects[idx] = simple_merge(rects[idx], rects[i]) |
| 195 | else: |
| 196 | idx += 1 |
| 197 | if idx != i: |
| 198 | rects[idx] = rects[i] |
| 199 | rects = rects[:idx + 1] |
| 200 | idx = 0 |
| 201 | while idx < len(rects): |
| 202 | left = idx + 1 |
| 203 | right = len(rects) - 1 |
| 204 | while left <= right: |
| 205 | if is_overlap_v2(rects[idx], rects[left], iou_threshold): |
| 206 | rects[idx] = simple_merge(rects[idx], rects[left]) |
| 207 | rects[left] = rects[right] |
| 208 | right -= 1 |
| 209 | else: |
| 210 | left += 1 |
| 211 | if len(rects) != right + 1: |
| 212 | rects = rects[:right + 1] |
| 213 | idx += 1 |
| 214 | return [x[5] for x in rects] |
nothing calls this directly
no test coverage detected