1. 使用原版预测
代码如下:
from ultralytics import YOLO
# Load a model
model = YOLO('yolov8n.pt') # load an official model
# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg') # predict on an image
命令如下:
yolo detect predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg' # predict with official model
2.使用自己的模型
仅需要把自己的模型放入即可
代码如下:
from ultralytics import YOLO
# Load a model
model = YOLO('path/to/best.pt') # load a custom model
# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg') # predict on an image
命令如下:
yolo detect predict model=path/to/best.pt source='https://ultralytics.com/images/bus.jpg'
会输出一下信息
3.如何让图片保存下来
添加save=True即可,代码如下:
from ultralytics import YOLO
# Load a model
model = YOLO('path/to/best.pt') # load a custom model
# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg', save=True) # predict on an image
会提示保存的路径