Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

nms.py 864 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  1. import numpy as np
  2. def nms(x1, y1, x2, y2, scores, thresh):
  3. """
  4. Non-Maximum Suppression
  5. x1,y1,x2,y2,scores np.ndarray of box coords with the same length
  6. returns indexes of boxes
  7. """
  8. keep = []
  9. if len(x1) == 0:
  10. return keep
  11. areas = (x2 - x1 + 1) * (y2 - y1 + 1)
  12. order = scores.argsort()[::-1]
  13. keep = []
  14. while order.size > 0:
  15. i = order[0]
  16. keep.append(i)
  17. xx_1, yy_1 = np.maximum(x1[i], x1[order[1:]]), np.maximum(y1[i], y1[order[1:]])
  18. xx_2, yy_2 = np.minimum(x2[i], x2[order[1:]]), np.minimum(y2[i], y2[order[1:]])
  19. width, height = np.maximum(0.0, xx_2 - xx_1 + 1), np.maximum(0.0, yy_2 - yy_1 + 1)
  20. ovr = width * height / (areas[i] + areas[order[1:]] - width * height)
  21. inds = np.where(ovr <= thresh)[0]
  22. order = order[inds + 1]
  23. return keep
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...