diff options
author | carp <25677564+carp@users.noreply.github.com> | 2020-07-13 13:27:55 -0400 |
---|---|---|
committer | carp <25677564+carp@users.noreply.github.com> | 2020-07-13 13:27:55 -0400 |
commit | cb961ed0d6896309336159bda34ed2f75fb60a84 (patch) | |
tree | 6d75fcd9bd32b2e884e299ea97e361513036b3a2 /anime-face-detector/nms/gpu_nms.pyx | |
parent | e78f351e06e432a607ebadc8de3ea6d27315c088 (diff) | |
download | yaoi-communism-cb961ed0d6896309336159bda34ed2f75fb60a84.tar.gz yaoi-communism-cb961ed0d6896309336159bda34ed2f75fb60a84.zip |
add face detection
Diffstat (limited to 'anime-face-detector/nms/gpu_nms.pyx')
-rw-r--r-- | anime-face-detector/nms/gpu_nms.pyx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/anime-face-detector/nms/gpu_nms.pyx b/anime-face-detector/nms/gpu_nms.pyx new file mode 100644 index 0000000..55878db --- /dev/null +++ b/anime-face-detector/nms/gpu_nms.pyx @@ -0,0 +1,31 @@ +# -------------------------------------------------------- +# Faster R-CNN +# Copyright (c) 2015 Microsoft +# Licensed under The MIT License [see LICENSE for details] +# Written by Ross Girshick +# -------------------------------------------------------- + +import numpy as np +cimport numpy as np + +assert sizeof(int) == sizeof(np.int32_t) + +cdef extern from "gpu_nms.hpp": + void _nms(np.int32_t*, int*, np.float32_t*, int, int, float, int) + +def gpu_nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh, + np.int32_t device_id=0): + cdef int boxes_num = dets.shape[0] + cdef int boxes_dim = dets.shape[1] + cdef int num_out + cdef np.ndarray[np.int32_t, ndim=1] \ + keep = np.zeros(boxes_num, dtype=np.int32) + cdef np.ndarray[np.float32_t, ndim=1] \ + scores = dets[:, 4] + cdef np.ndarray[np.int64_t, ndim=1] \ + order = scores.argsort()[::-1] + cdef np.ndarray[np.float32_t, ndim=2] \ + sorted_dets = dets[order, :] + _nms(&keep[0], &num_out, &sorted_dets[0, 0], boxes_num, boxes_dim, thresh, device_id) + keep = keep[:num_out] + return list(order[keep]) |