1. nms

  1. def py_cpu_nms(dets, thresh):
  2. x1 = dets[:,0]
  3. y1 = dets[:,1]
  4. x2 = dets[:,2]
  5. y2 = dets[:,3]
  6. areas = (y2-y1+1) * (x2-x1+1)
  7. scores = dets[:,4]
  8. keep = []
  9. index = scores.argsort()[::-1]
  10. while index.size >0:
  11. i = index[0] # every time the first is the biggst, and add it directly
  12. keep.append(i)
  13. x11 = np.maximum(x1[i], x1[index[1:]]) # calculate the points of overlap
  14. y11 = np.maximum(y1[i], y1[index[1:]])
  15. x22 = np.minimum(x2[i], x2[index[1:]])
  16. y22 = np.minimum(y2[i], y2[index[1:]])
  17. w = np.maximum(0, x22-x11+1) # the weights of overlap
  18. h = np.maximum(0, y22-y11+1) # the height of overlap
  19. overlaps = w*h
  20. ious = overlaps / (areas[i]+areas[index[1:]] - overlaps)
  21. idx = np.where(ious<=thresh)[0]
  22. index = index[idx+1] # because index start from 1
  23. return keep

2. xxxx

3. xxxx

4. xxxx

References

链接 链接