CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hukaixuan19970627

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: hukaixuan19970627/yolov5_obb
Path: blob/master/DOTA_devkit/poly_nms_gpu/poly_nms.pyx
Views: 475
1
import numpy as np
2
cimport numpy as np
3
4
assert sizeof(int) == sizeof(np.int32_t)
5
6
cdef extern from "poly_nms.hpp":
7
void _poly_nms(np.int32_t*, int*, np.float32_t*, int, int, float, int)
8
9
def poly_gpu_nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh,
10
np.int32_t device_id=0):
11
cdef int boxes_num = dets.shape[0]
12
cdef int boxes_dim = dets.shape[1]
13
cdef int num_out
14
cdef np.ndarray[np.int32_t, ndim=1] \
15
keep = np.zeros(boxes_num, dtype=np.int32)
16
cdef np.ndarray[np.float32_t, ndim=1] \
17
scores = dets[:, 8]
18
cdef np.ndarray[np.int_t, ndim=1] \
19
order = scores.argsort()[::-1]
20
cdef np.ndarray[np.float32_t, ndim=2] \
21
sorted_dets = dets[order, :]
22
_poly_nms(&keep[0], &num_out, &sorted_dets[0, 0], boxes_num, boxes_dim, thresh, device_id)
23
keep = keep[:num_out]
24
return list(order[keep])
25
26