UltralyticsYOLOv8_ultralytics使用(1)

本文介绍了如何使用 Ultralytics 的 YOLOv8n 模型进行图像和视频的实时推理,包括从 RTSP、RTMP 等流媒体地址处理多个流。此外,还详细展示了模型的训练过程,涵盖单GPU及多GPU训练,以及模型验证和导出。最后,提供了代码示例以展示如何在Python中加载和使用预训练的YOLOv8n模型进行目标检测、分割、姿态估计和分类任务。
摘要由CSDN通过智能技术生成

或者定义一个包括子目录在内的递归 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

  • 21
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值