@@ -32,8 +32,6 @@ void check_cuda(cudaError_t status) {
3232#endif
3333
3434struct detector_gpu_t {
35- float **probs;
36- box *boxes;
3735 network net;
3836 image images[FRAMES];
3937 float *avg;
@@ -79,10 +77,6 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
7977 for (j = 0 ; j < FRAMES; ++j) detector_gpu.predictions [j] = (float *)calloc (l.outputs , sizeof (float ));
8078 for (j = 0 ; j < FRAMES; ++j) detector_gpu.images [j] = make_image (1 , 1 , 3 );
8179
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-
8680 detector_gpu.track_id = (unsigned int *)calloc (l.classes , sizeof (unsigned int ));
8781 for (j = 0 ; j < l.classes ; ++j) detector_gpu.track_id [j] = 1 ;
8882
@@ -103,14 +97,9 @@ YOLODLL_API Detector::~Detector()
10397 for (int j = 0 ; j < FRAMES; ++j) free (detector_gpu.predictions [j]);
10498 for (int j = 0 ; j < FRAMES; ++j) if (detector_gpu.images [j].data ) free (detector_gpu.images [j].data );
10599
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-
110100 int old_gpu_index;
111101#ifdef GPU
112102 cudaGetDevice (&old_gpu_index);
113- // cudaSetDevice(detector_gpu.net.gpu_index);
114103 cuda_set_device (detector_gpu.net .gpu_index );
115104#endif
116105
@@ -225,17 +214,21 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
225214 l.output = detector_gpu.avg ;
226215 detector_gpu.demo_index = (detector_gpu.demo_index + 1 ) % FRAMES;
227216 }
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);
228219
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);
232225
233226 std::vector<bbox_t > bbox_vec;
234227
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];
239232
240233 if (prob > thresh)
241234 {
@@ -252,6 +245,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
252245 }
253246 }
254247
248+ free_detections (dets, nboxes);
255249 if (sized.data )
256250 free (sized.data );
257251
0 commit comments