或者定义一个包括子目录在内的递归 glob 搜索,以查找所有 JPG 文件
source = ‘path/to/dir/**/*.jpg’
Run inference on the source
results = model(source, stream=True) # generator of Results objects
**12.YouTube**:对 YouTube 视频进行推理通过使用 stream=True此外,您还可以创建一个结果对象生成器,以减少长视频的内存使用量。
from ultralytics import YOLO
Load a pretrained YOLOv8n model
model = YOLO(‘yolov8n.pt’)
Define source as YouTube video URL
source = ‘https://youtu.be/LNwODJXcvt4’
Run inference on the source
results = model(source, stream=True) # generator of Results objects
**13.Steams流**:使用 RTSP、RTMP、TCP 和 IP 地址协议对远程流媒体源进行推理。如果在一个 \*.streams 文本文件,则将运行批处理推理,即 8 个数据流将以 8 的批处理大小运行,否则单个数据流将以 1 的批处理大小运行。
from ultralytics import YOLO
Load a pretrained YOLOv8n model
model = YOLO(‘yolov8n.pt’)
Single stream with batch-size 1 inference
单个流,批处理大小为1的推理
source = ‘rtsp://example.com/media.mp4’ # RTSP, RTMP, TCP or IP streaming address
RTSP,RTMP,TCP或IP流地址
Multiple streams with batched inference (i.e. batch-size 8 for 8 streams)
多个流,批处理推理(例如,8个流的批处理大小为8)
source = ‘path/to/list.streams’ # *.streams text file with one streaming address per row
*.streams文本文件,每行一个流地址
Run inference on the source
results = model(source, stream=True) # generator of Results objects
### Working with Results
from ultralytics import YOLO
Load a pretrained YOLOv8n model
加载预训练的YOLOv8n模型
model = YOLO(‘yolov8n.pt’)
Run inference on an image
对一张图片进行推理
results = model(‘bus.jpg’) # list of 1 Results object
结果是一个Results对象的列表,其中包含1个对象
results = model([‘bus.jpg’, ‘zidane.jpg’]) # list of 2 Results objects
结果是一个Results对象的列表,其中包含2个对象
**1.Boxes**:oxes 对象可用于索引、操作和将边界框转换为不同格式。
from ultralytics import YOLO
Load a pretrained YOLOv8n model
model = YOLO(‘yolov8n.pt’)
Run inference on an image
results = model(‘bus.jpg’) # results list
View results
for r in results:
print(r.boxes) # print the Boxes object containing the detection bounding boxes
# 打印包含检测边界框的 Boxes 对象
**1.Masks**:Masks 对象可用于索引、操作和将掩码转换为线段。
from ultralytics import YOLO
Load a pretrained YOLOv8n-seg Segment model
model = YOLO(‘yolov8n-seg.pt’) # 加载预训练的 YOLOv8n-seg 分割模型
Run inference on an image
results = model(‘bus.jpg’) # 在一张图片上进行推理,返回结果列表
View results
for r in results:
print(r.masks) # 打印包含检测到的实例掩码的 Masks 对象
**3.Keypoints**:Keypoints 对象可用于索引、处理和归一化坐标。
from ultralytics import YOLO
Load a pretrained YOLOv8n-pose Pose model
加载预训练的 YOLOv8n-pose 姿势模型
model = YOLO(‘yolov8n-pose.pt’)
Run inference on an image
在一张图像上运行推理
results = model(‘bus.jpg’) # results list
View results
查看结果
for r in results:
print(r.keypoints) # print the Keypoints object containing the detected keypoints
# 打印包含检测到的关键点的 Keypoints 对象
**4.Probs**:Probs 对象可用于索引、获取 top1 和 top5 分类指数和分数。
from ultralytics import YOLO
Load a pretrained YOLOv8n-cls Classify model
加载预训练的 YOLOv8n-cls 分类模型
model = YOLO(‘yolov8n-cls.pt’)
Run inference on an image
在一张图片上进行推断
results = model(‘bus.jpg’) # results list
View results
查看结果
for r in results:
print(r.probs) # print the Probs object containing the detected class probabilities
# 打印包含检测到的类别概率的 Probs 对象
**5.OBB**:OBB 对象可用于索引、操作和将定向边界框转换为不同格式。
from ultralytics import YOLO
Load a pretrained YOLOv8n model
model = YOLO(‘yolov8n-obb.pt’)
Run inference on an image
results = model(‘bus.jpg’) # results list