Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import numpy as np
  2. import cupy as cp
  3.  
  4.  
  5. def _non_maximum_suppression_cpu(bbox, thresh, score=None, limit=None):
  6. bbox = cp.asnumpy(bbox)
  7. if len(bbox) == 0:
  8. return np.zeros((0,), dtype=np.int32)
  9.  
  10. if score is not None:
  11. order = score.argsort()[::-1]
  12. bbox = bbox[order]
  13. bbox_area = np.prod(bbox[:, 2:] - bbox[:, :2], axis=1) #面積求めてる。
  14.  
  15. selec = np.zeros(bbox.shape[0], dtype=bool)
  16. for i, b in enumerate(bbox):
  17. tl = np.maximum(b[:2], bbox[selec, :2])
  18. br = np.minimum(b[2:], bbox[selec, 2:])
  19. area = np.prod(br - tl, axis=1) * (tl < br).all(axis=1)
  20.  
  21. iou = area / (bbox_area[i] + bbox_area[selec] - area)
  22. if (iou >= thresh).any():
  23. continue
  24.  
  25. selec[i] = True
  26. if limit is not None and np.count_nonzero(selec) >= limit:
  27. break
  28. selec = np.where(selec)[0]
  29. if score is not None:
  30. selec = order[selec]
  31. return selec.astype(np.int32)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement