Franpper 2023-11-07 16:25 采纳率: 25%
浏览 156

YOLOv8追踪内存占用过大问题

yolov8追踪时,30s帧率为30的一个视频,在追踪过程中提交内存达到了40G,12G显存也快占满了,是yolov8的计算量就这么大吗,有什么不降低速度和精度的办法来减少占用内存吗?麻烦解答一下

用的是yolov8官方提供的代码:

import cv2
from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO('yolov8n.pt')

# Open the video file
video_path = "path/to/video.mp4"
cap = cv2.VideoCapture(video_path)

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        # Run YOLOv8 tracking on the frame, persisting tracks between frames
        results = model.track(frame, persist=True)

        # Visualize the results on the frame
        annotated_frame = results[0].plot()

        # Display the annotated frame
        cv2.imshow("YOLOv8 Tracking", annotated_frame)

        # Break the loop if 'q' is pressed
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # Break the loop if the end of the video is reached
        break

# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

  • 写回答

2条回答 默认 最新

  • qwqqq2 2023-11-07 18:25
    关注

    results可能会占用大量内存,尤其是当results包含大量检测和追踪信息时。如果你确信某个对象之后不会再被使用,可以使用del关键字来删除这个对象,之后调用gc.collect()来显式触发垃圾回收。

    
    del results
    del annotated_frame  
    gc.collect() 
    
    评论

报告相同问题?

问题事件

  • 创建了问题 11月7日

悬赏问题

  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真