首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Darknet Yolov4 Python内存泄漏

Darknet Yolov4 Python内存泄漏
EN

Stack Overflow用户
提问于 2021-10-17 04:33:30
回答 1查看 69关注 0票数 0

我在运行darknet.py提供的detect_image(...)时遇到了内存泄漏。我在没完没了的while循环中检测对象。我使用的是Ubuntu20.04、Python3.8.10、OpenCV 4.5.2和Cuda10.2。

EN

回答 1

Stack Overflow用户

发布于 2021-10-17 04:33:30

darknet.py已经有一个函数来处理这个问题,也就是free_image(image)。由于某些原因,这不会在函数detect_image(...)中调用。我已经在free_detections(detections, num)下面添加了这个,内存泄漏已经解决了。下面是确切的代码:

代码语言:javascript
复制
def detect_image(network, class_names, image_path, thresh=.5, hier_thresh=.5, nms=.45):
    """
        Returns a list with highest confidence class and their bbox
    """
    pnum = pointer(c_int(0))
    image = load_image(image_path,0,0)
    predict_image(network, image)
    detections = get_network_boxes(network, image.w, image.h,
                                   thresh, hier_thresh, None, 0, pnum, 0)
    num = pnum[0]
    if nms:
        do_nms_sort(detections, num, len(class_names), nms)
    predictions = remove_negatives(detections, class_names, num)
    predictions = decode_detection(predictions)
    free_detections(detections, num)
    free_image(image) # this was missing...
    return sorted(predictions, key=lambda x: x[1])```
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69601339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档