赞
踩
STREAM_WARNING = “”"
WARNING ⚠️ inference results will accumulate in RAM unlessstream=True
is passed, causing potential out-of-memory
errors for large sources or long-running streams and videos. See https://docs.ultralytics.com/modes/predict/ for help.
当我们不做任何设置的时候,会有这样的一个提示。
我之前的yolov8代码是这样的,直接这样设置stream=True参数是无法运行程序的
from ultralytics import YOLO
import os
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
if __name__ == '__main__':
#预测结果
model = YOLO('yolov8n-pose.pt')
model.predict('0', save=True,stream=True)
需要把代码成下面的,这样运行摄像头检测,内存就不会一直上升,导致内存泄漏了。
import os
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
from ultralytics import YOLO
model = YOLO("yolov8n-pose.pt")
results = model(source=0, stream=True,show=True) # generator of Results objects
for r in results:
boxes = r.boxes # Boxes object for bbox outputs
masks = r.masks # Masks object for segment masks outputs
probs = r.probs # Class probabilities for classification outputs
本文章由微智启编写,转载标明出处。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。