@@ -32,8 +32,6 @@ void check_cuda(cudaError_t status) {
32
32
#endif
33
33
34
34
struct detector_gpu_t {
35
- float **probs;
36
- box *boxes;
37
35
network net;
38
36
image images[FRAMES];
39
37
float *avg;
@@ -79,10 +77,6 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
79
77
for (j = 0 ; j < FRAMES; ++j) detector_gpu.predictions [j] = (float *)calloc (l.outputs , sizeof (float ));
80
78
for (j = 0 ; j < FRAMES; ++j) detector_gpu.images [j] = make_image (1 , 1 , 3 );
81
79
82
- detector_gpu.boxes = (box *)calloc (l.w *l.h *l.n , sizeof (box));
83
- detector_gpu.probs = (float **)calloc (l.w *l.h *l.n , sizeof (float *));
84
- for (j = 0 ; j < l.w *l.h *l.n ; ++j) detector_gpu.probs [j] = (float *)calloc (l.classes , sizeof (float ));
85
-
86
80
detector_gpu.track_id = (unsigned int *)calloc (l.classes , sizeof (unsigned int ));
87
81
for (j = 0 ; j < l.classes ; ++j) detector_gpu.track_id [j] = 1 ;
88
82
@@ -103,14 +97,9 @@ YOLODLL_API Detector::~Detector()
103
97
for (int j = 0 ; j < FRAMES; ++j) free (detector_gpu.predictions [j]);
104
98
for (int j = 0 ; j < FRAMES; ++j) if (detector_gpu.images [j].data ) free (detector_gpu.images [j].data );
105
99
106
- for (int j = 0 ; j < l.w *l.h *l.n ; ++j) free (detector_gpu.probs [j]);
107
- free (detector_gpu.boxes );
108
- free (detector_gpu.probs );
109
-
110
100
int old_gpu_index;
111
101
#ifdef GPU
112
102
cudaGetDevice (&old_gpu_index);
113
- // cudaSetDevice(detector_gpu.net.gpu_index);
114
103
cuda_set_device (detector_gpu.net .gpu_index );
115
104
#endif
116
105
@@ -225,17 +214,21 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
225
214
l.output = detector_gpu.avg ;
226
215
detector_gpu.demo_index = (detector_gpu.demo_index + 1 ) % FRAMES;
227
216
}
217
+ // get_region_boxes(l, 1, 1, thresh, detector_gpu.probs, detector_gpu.boxes, 0, 0);
218
+ // if (nms) do_nms_sort(detector_gpu.boxes, detector_gpu.probs, l.w*l.h*l.n, l.classes, nms);
228
219
229
- get_region_boxes (l, 1 , 1 , thresh, detector_gpu.probs , detector_gpu.boxes , 0 , 0 );
230
- if (nms) do_nms_sort (detector_gpu.boxes , detector_gpu.probs , l.w *l.h *l.n , l.classes , nms);
231
- // draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, names, alphabet, l.classes);
220
+ int nboxes = 0 ;
221
+ int letterbox = 0 ;
222
+ float hier_thresh = 0.5 ;
223
+ detection *dets = get_network_boxes (&net, im.w , im.h , thresh, hier_thresh, 0 , 1 , &nboxes, letterbox);
224
+ if (nms) do_nms_sort_v3 (dets, nboxes, l.classes , nms);
232
225
233
226
std::vector<bbox_t > bbox_vec;
234
227
235
- for (size_t i = 0 ; i < (l. w *l. h *l. n ) ; ++i) {
236
- box b = detector_gpu. boxes [i];
237
- int const obj_id = max_index (detector_gpu. probs [i], l.classes );
238
- float const prob = detector_gpu. probs [i][obj_id];
228
+ for (size_t i = 0 ; i < nboxes ; ++i) {
229
+ box b = dets [i]. bbox ;
230
+ int const obj_id = max_index (dets [i]. prob , l.classes );
231
+ float const prob = dets [i]. prob [obj_id];
239
232
240
233
if (prob > thresh)
241
234
{
@@ -252,6 +245,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
252
245
}
253
246
}
254
247
248
+ free_detections (dets, nboxes);
255
249
if (sized.data )
256
250
free (sized.data );
257
251
0 commit comments