digitalbrain79 / pyyolo

Simple python wrapper for YOLO.
126 stars 65 forks source link

Memory leak on libyolo.c get_network_boxes #42

Open zivCheng opened 6 years ago

zivCheng commented 6 years ago

`detection_info *yolo_detect(yolo_handle handle, image im, float thresh, float hier_thresh, int num) { yolo_obj obj = (yolo_obj )handle; image sized = letterbox_image(im, obj->net->w, obj->net->h);

float *X = sized.data;
clock_t time;
time=clock();
network_predict(obj->net, X);
printf("Cam frame predicted in %f seconds.\n", sec(clock()-time));

layer l = obj->net->layers[obj->net->n-1];

int nboxes = 0;
detection *dets = get_network_boxes(obj->net, im.w, im.h, thresh, hier_thresh, 0, 1, &nboxes);
if (obj->nms) do_nms_sort(dets, nboxes, l.classes, obj->nms);

list *output = make_list();
get_detection_info(im, nboxes, thresh, dets, l.classes, obj->names, output);
detection_info **info = (detection_info **)list_to_array(output);
*num = output->size;

free_list(output);
free_image(sized);

//Add this line to fix the memory leak issue
free_detections(dets, nboxes);

return info;

}`