MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / nms

Function nms

flow-python/examples/application/utils.py:172–214  ·  view source on GitHub ↗
(boxes, scores, iou_threshold=0.3)

Source from the content-addressed store, hash-verified

170
171
172def 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]

Callers

nothing calls this directly

Calls 5

listFunction · 0.85
rangeFunction · 0.85
is_overlap_v2Function · 0.85
simple_mergeFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected