Meet YOLO26: next-gen vision AI.

Link to this section目标检测#

YOLO object detection with bounding boxes

目标检测是一项涉及识别图像或视频流中对象位置和类别的任务。

目标检测器的输出是一组包围图像中对象的边界框,以及每个框的类别标签和置信度分数。当你需要识别场景中的目标对象,但不需要确切知道该对象的位置或其精确形状时,目标检测是一个不错的选择。



Watch: Object Detection with Pretrained Ultralytics YOLO Model.
提示

YOLO26 Detect 模型是默认的 YOLO26 模型,即yolo26n.pt,它们是在COCO数据集上预训练的。

Link to this section模型#

这里展示了 YOLO26 预训练的 Detect 模型。Detect、Segment 和 Pose 模型是在COCO数据集上预训练的,Semantic模型是在Cityscapes上预训练的,而 Classify 模型是在ImageNet数据集上预训练的。

模型在首次使用时会自动从最新的 Ultralytics 发布版本下载。

模型尺寸
(像素)
mAPval
50-95
mAPval
50-95(e2e)
速度
CPU ONNX
(ms)
速度
T4 TensorRT10
(ms)
参数
(M)
FLOPs
(B)
YOLO26n64040.940.138.9 ± 0.71.7 ± 0.02.45.4
YOLO26s64048.647.887.2 ± 0.92.5 ± 0.09.520.7
YOLO26m64053.152.5220.0 ± 1.44.7 ± 0.120.468.2
YOLO26l64055.054.4286.2 ± 2.06.2 ± 0.224.886.4
YOLO26x64057.556.9525.8 ± 4.011.8 ± 0.255.7193.9
  • mAPval 数值是针对COCO val2017数据集上的单模型单尺度结果。
    通过运行 yolo val detect data=coco.yaml device=0 进行复现。
  • 速度是通过使用Amazon EC2 P4d实例对 COCO val 图像进行平均得出的。
    通过运行 yolo val detect data=coco.yaml batch=1 device=0|cpu 进行复现。
  • 参数FLOPs数值是针对执行 model.fuse() 后的融合模型,该操作合并了 Conv 和 BatchNorm 层,对于端到端模型,它移除了辅助的一对多检测头。预训练检查点保留了完整的训练架构,数值可能会更高。

Link to this section训练#

在 COCO8 数据集上,以 640 的图像尺寸训练 YOLO26n 模型 100 个epoch。如需查看可用参数的完整列表,请参阅配置页面。

示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.yaml")  # build a new model from YAML
model = YOLO("yolo26n.pt")  # load a pretrained model (recommended for training)
model = YOLO("yolo26n.yaml").load("yolo26n.pt")  # build from YAML and transfer weights

# Train the model
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

See full train mode details in the Train page. Detection models can also be trained on cloud GPUs through Ultralytics Platform.

Link to this section数据集格式#

YOLO 检测数据集格式的详细信息可以在数据集指南中找到。要将现有数据集从其他格式(如 COCO 等)转换为 YOLO 格式,请使用 Ultralytics 提供的JSON2YOLO工具。你还可以通过Ultralytics 平台使用 AI 辅助标注工具直接标注和管理检测数据集。

Link to this section验证#

Validate trained YOLO26n model accuracy on the COCO8 dataset. No arguments are needed as the model retains its training data and arguments as model attributes.

示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Validate the model
metrics = model.val()  # no arguments needed, dataset and settings remembered
metrics.box.map  # map50-95
metrics.box.map50  # map50
metrics.box.map75  # map75
metrics.box.maps  # a list containing mAP50-95 for each category
metrics.box.image_metrics  # per-image metrics dictionary with precision, recall, F1, TP, FP, and FN

Link to this section预测#

使用已训练的 YOLO26n 模型对图像运行预测。

示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load an official 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

# Access the results
for result in results:
    xywh = result.boxes.xywh  # center-x, center-y, width, height
    xywhn = result.boxes.xywhn  # normalized
    xyxy = result.boxes.xyxy  # top-left-x, top-left-y, bottom-right-x, bottom-right-y
    xyxyn = result.boxes.xyxyn  # normalized
    names = [result.names[cls.item()] for cls in result.boxes.cls.int()]  # class name of each box
    confs = result.boxes.conf  # confidence score of each box

See full predict mode details in the Predict page.

Link to this section结果输出#

目标检测为每张图像返回一个 Results 对象。主要的预测字段是 result.boxes,其中包含每个检测到对象的目标框坐标、类别 ID 和置信度分数。

属性类型形状描述
result.boxesBoxes(N)检测框。
result.boxes.datatorch.float32(N,6/7)原始 [x1,y1,x2,y2,conf,cls],外加可选的跟踪 ID。
result.boxes.xyxytorch.float32(N,4)xyxy 像素框。
result.boxes.conftorch.float32(N,)置信度分数。
result.boxes.clstorch.float32(N,)类别 ID;转换为 int 以获取名称。

有关各任务特定的 Results 字段,请参阅按任务预测结果部分。

Link to this section导出#

将 YOLO26n 模型导出为其他格式,如 ONNX、CoreML 等。

示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom-trained model

# Export the model
model.export(format="onnx")

可用的 YOLO26 导出格式如下表所示。你可以使用 format 参数导出为任何格式,例如 format='onnx'format='engine'。你可以直接在导出的模型上进行预测或验证,例如 yolo predict model=yolo26n.onnx。导出完成后,会显示针对你模型的用法示例。

格式format 参数模型元数据参数
PyTorch-yolo26n.pt-
TorchScripttorchscriptyolo26n.torchscriptimgsz, half, dynamic, optimize, nms, batch, device
ONNXonnxyolo26n.onnximgsz, half, int8, dynamic, simplify, opset, nms, batch, data, fraction, device
OpenVINOopenvinoyolo26n_openvino_model/imgsz, half, dynamic, int8, nms, batch, data, fraction, device
TensorRTengineyolo26n.engineimgsz, half, dynamic, simplify, workspace, int8, nms, batch, data, fraction, device
CoreMLcoremlyolo26n.mlpackageimgsz, dynamic, half, int8, nms, batch, device
TF SavedModelsaved_modelyolo26n_saved_model/imgsz, keras, int8, nms, batch, data, fraction, device
TF GraphDefpbyolo26n.pbimgsz, batch, device
TF Litetfliteyolo26n.tfliteimgsz, half, int8, nms, batch, data, fraction, device
TF Edge TPUedgetpuyolo26n_edgetpu.tfliteimgsz, int8, data, fraction, device
TF.jstfjsyolo26n_web_model/imgsz, half, int8, nms, batch, data, fraction, device
PaddlePaddlepaddleyolo26n_paddle_model/imgsz, batch, device
MNNmnnyolo26n.mnnimgsz, batch, int8, half, device
NCNNncnnyolo26n_ncnn_model/imgsz, half, batch, device
IMX500imxyolo26n_imx_model/imgsz, int8, data, fraction, nms, device
RKNNrknnyolo26n_rknn_model/imgsz, batch, name, int8, data, fraction, device
ExecuTorchexecutorchyolo26n_executorch_model/imgsz, batch, device
Axeleraaxelerayolo26n_axelera_model/imgsz, batch, int8, data, fraction, device
DEEPXdeepxyolo26n_deepx_model/imgsz, int8, data, optimize, device
Qualcomm QNNqnnyolo26n_qnn_model/imgsz, batch, name, int8, data, fraction, device

See full export details in the Export page.

Link to this section常见问题解答 (FAQ)#

Link to this section我可以在不编写代码的情况下训练和部署检测模型吗?#

可以。Ultralytics Platform 提供了基于浏览器的工作流程,用于标注数据集、在云端 GPU 上训练检测模型并将其部署到推理端点。请参阅 Platform quickstart 开始使用。

Link to this section如何在我自己的数据集上训练 YOLO26 模型?#

在自定义数据集上训练 YOLO26 模型包含以下几个步骤:

  1. 准备数据集:确保你的数据集采用 YOLO 格式。有关指南,请参考我们的 Dataset Guide
  2. 加载模型:使用 Ultralytics YOLO 库加载预训练模型,或从 YAML 文件创建新模型。
  3. 训练模型:在 Python 中执行 train 方法,或在 CLI 中执行 yolo detect train 命令。
示例
from ultralytics import YOLO

# Load a pretrained model
model = YOLO("yolo26n.pt")

# Train the model on your custom dataset
model.train(data="my_custom_dataset.yaml", epochs=100, imgsz=640)

有关详细配置选项,请访问 Configuration 页面。

Link to this sectionYOLO26 中有哪些可用的预训练模型?#

Ultralytics YOLO26 提供了各种预训练模型,适用于 object detectioninstance segmentationsemantic segmentationpose estimation。这些模型是在 COCO 数据集、用于语义分割的 Cityscapes 数据集,或用于分类任务的 ImageNet 数据集上预训练的。以下是一些可用模型:

有关详细列表和性能指标,请参阅 Models 部分。

Link to this section我该如何验证已训练的 YOLO 模型的准确性?#

要验证已训练的 YOLO26 模型的准确性,你可以在 Python 中使用 .val() 方法,或在 CLI 中使用 yolo detect val 命令。这将提供 mAP50-95、mAP50 等指标。

示例
from ultralytics import YOLO

# Load the model
model = YOLO("path/to/best.pt")

# Validate the model
metrics = model.val()
print(metrics.box.map)  # mAP50-95

有关更多验证详细信息,请访问 Val 页面。

Link to this sectionYOLO26 模型可以导出为哪些格式?#

Ultralytics YOLO26 允许将模型导出为 ONNXTensorRTCoreML 等多种格式,以确保在不同平台和设备上的兼容性。

示例
from ultralytics import YOLO

# Load the model
model = YOLO("yolo26n.pt")

# Export the model to ONNX format
model.export(format="onnx")

Export 页面查看支持的格式完整列表和说明。

Link to this section为什么我应该使用 Ultralytics YOLO26 进行目标检测?#

Ultralytics YOLO26 旨在为 object detectioninstance segmentationsemantic segmentationpose estimation 提供最先进的性能。以下是一些主要优势:

  1. 预训练模型:利用在 COCOImageNet 等热门数据集上预训练的模型,实现更快的开发。
  2. 高准确率:实现出色的 mAP 分数,确保可靠的目标检测。
  3. 速度:针对 real-time inference 进行了优化,使其成为需要快速处理的应用的理想选择。
  4. 灵活性:将模型导出为 ONNX 和 TensorRT 等各种格式,以便在多个平台上部署。

探索我们的 Blog,了解 YOLO26 的实际应用案例和成功故事。

评论