【问题描述】执行YOLOv8预测代码时:
# 导入训练好的权重文件做预测
from ultralytics import YOLO
# Load a pretrained YOLOv8n model
model = YOLO("/data/yolov8/runs/detect/train6/weights/best.pt")
# Run inference on 'bus.jpg' with arguments
model.predict("1.png", save=True, imgsz=640, conf=0.5)
报错:ValueError: AutoBatch with batch<1 not supported for Multi-GPU training, please specify a valid batch size, i.e. batch=16
【解决方案】
在执行model.predict时指定device:
# 导入训练好的权重文件做预测
from ultralytics import YOLO
# Load a pretrained YOLOv8n model
model = YOLO("/data/ctc/yolov8/runs/detect/train6/weights/best.pt")
# Run inference on 'bus.jpg' with arguments
model.predict("1.png", save=True, imgsz=640, conf=0.5, device='cpu')
问题成功解决。