Meet YOLO26: next-gen vision AI.

Link to this section语义分割#

Semantic segmentation examples

语义分割为图像中的每个像素分配一个类标签,生成覆盖整个场景的密集类图。与将单个对象分离开来的实例分割不同,语义分割将同一类的所有像素归为一组,无论是否存在多个独立对象。

语义分割模型的输出是一个高度乘以宽度的单通道类图,其中每个像素值对应一个预测出的类别 ID。这使得语义分割非常适合场景解析任务,例如自动驾驶、医学成像和土地覆盖测绘。

提示

使用 task=semanticyolo semantic CLI 任务进行语义分割。YOLO26 语义分割模型文件使用 -sem 后缀,例如 yolo26n-sem.pt

Link to this section模型#

Cityscapes 数据集上预训练的 YOLO26 语义分割模型如下所示。

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

模型尺寸
(像素)
mIoUval速度
RTX3090 PyTorch
(ms)
参数
(M)
FLOPs
(B)
YOLO26n-sem1024 × 204878.34.4 ± 0.01.622.7
YOLO26s-sem1024 × 204880.88.4 ± 0.06.588.8
YOLO26m-sem1024 × 204882.019.9 ± 0.114.3304.5
YOLO26l-sem1024 × 204882.926.5 ± 0.117.9384.7
YOLO26x-sem1024 × 204883.648.9 ± 0.240.2861.7
  • mIoUval 值是在 Cityscapes 验证集上进行的单模型单尺度测试。
    使用 yolo semantic val data=cityscapes.yaml device=0 imgsz=2048 进行复现。
  • 速度指标是在 RTX3090 实例上对 Cityscapes 验证图像进行平均的结果。
    使用 yolo semantic val data=cityscapes.yaml batch=1 device=0|cpu imgsz=2048 进行复现。
  • 参数FLOPs 值针对 model.fuse() 融合后的模型,该操作合并了 Conv 和 BatchNorm 层。预训练检查点保留了完整的训练架构,因此计数值可能会更高。

Link to this section训练#

在 Cityscapes8 数据集上以 1024 图像尺寸训练 YOLO26n-sem 100 个 epoch。有关可用参数的完整列表,请查看配置页面。

示例
from ultralytics import YOLO

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

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

See full train mode details in the Train page.

Link to this section数据集格式#

语义分割数据集使用单通道掩码图像(通常为 PNG),其中每个像素值代表一个类 ID。值为 255 的像素被视为“忽略”并从损失计算中排除。数据集 YAML 文件应指定图像及其对应掩码目录的路径。有关格式详细信息,请参阅语义分割数据集指南。支持的数据集包括 CityscapesADE20K

Link to this section验证#

在语义分割数据集上验证已训练的 YOLO26n-sem 模型准确率。请显式传递 data,以便验证过程使用预期的数据集 YAML。

示例
from ultralytics import YOLO

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

# Validate the model
metrics = model.val(data="cityscapes.yaml")
metrics.miou  # mean Intersection over Union
metrics.pixel_accuracy  # overall pixel accuracy

Link to this section预测#

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

示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n-sem.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:
    semantic_mask = result.semantic_mask.data  # class map, shape (H,W), integer dtype selected by class count

See full predict mode details in the Predict page.

Link to this section结果输出#

YOLO 语义分割为每张图像返回一个 Results 对象。每个结果存储一张覆盖整幅图像的密集类图,而不是一组对象掩码。具有相同预测类别的像素共享相同的类 ID,即使它们属于不同的对象。

属性类型形状描述
result.semantic_maskSemanticMask(H,W)密集类图。
result.semantic_mask.datatorch.uint8
torch.int16
torch.int32
(H,W)类 ID;数据类型由类别数量决定。
result.masks--无实例掩码。
result.boxes--无实例边界框/置信度。
result.masks.xy--无默认多边形。

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

Link to this section实例分割与语义分割对比#

方面实例分割 (task="segment")语义分割 (task="semantic")
预测目标分别分割每个检测到的对象为每个像素分配一个类 ID
输出字段result.masksresult.semantic_mask
主要数据result.masks.dataresult.semantic_mask.data
形状(N,H,W)(H,W)
形状Binary mask values: 0 or 1Class IDs: 0, 1, 2, ...
像素值torch.uint8torch.uint8
torch.int16
torch.int32
Same-class objects数据类型Merged into the same class region
同类对象Yes, through result.masks.xy and result.masks.xyn合并到同一类区域中
多边形Yes, through result.boxes默认无多边形输出
边界框和置信度Counting, tracking, cropping, object-level measurement无逐个实例的边界框或置信度分数

Link to this section导出#

典型用途

示例
from ultralytics import YOLO

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

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

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

格式format 参数模型元数据参数
PyTorch-yolo26n-sem.pt-
TorchScripttorchscriptyolo26n-sem.torchscriptimgsz, half, dynamic, optimize, nms, batch, device
ONNXonnxyolo26n-sem.onnximgsz, half, int8, dynamic, simplify, opset, nms, batch, data, fraction, device
OpenVINOopenvinoyolo26n-sem_openvino_model/imgsz, half, dynamic, int8, nms, batch, data, fraction, device
TensorRTengineyolo26n-sem.engineimgsz, half, dynamic, simplify, workspace, int8, nms, batch, data, fraction, device
CoreMLcoremlyolo26n-sem.mlpackageimgsz, dynamic, half, int8, nms, batch, device
TF SavedModelsaved_modelyolo26n-sem_saved_model/imgsz, keras, int8, nms, batch, data, fraction, device
TF GraphDefpbyolo26n-sem.pbimgsz, batch, device
TF Litetfliteyolo26n-sem.tfliteimgsz, half, int8, nms, batch, data, fraction, device
TF Edge TPUedgetpuyolo26n-sem_edgetpu.tfliteimgsz, int8, data, fraction, device
TF.jstfjsyolo26n-sem_web_model/imgsz, half, int8, nms, batch, data, fraction, device
PaddlePaddlepaddleyolo26n-sem_paddle_model/imgsz, batch, device
MNNmnnyolo26n-sem.mnnimgsz, batch, int8, half, device
NCNNncnnyolo26n-sem_ncnn_model/imgsz, half, batch, device
IMX500imxyolo26n-sem_imx_model/imgsz, int8, data, fraction, nms, device
RKNNrknnyolo26n-sem_rknn_model/imgsz, batch, name, int8, data, fraction, device
ExecuTorchexecutorchyolo26n-sem_executorch_model/imgsz, batch, device
Axeleraaxelerayolo26n-sem_axelera_model/imgsz, batch, int8, data, fraction, device
DEEPXdeepxyolo26n-sem_deepx_model/imgsz, int8, data, optimize, device
Qualcomm QNNqnnyolo26n-sem_qnn_model/imgsz, batch, name, int8, data, fraction, device

See full export details in the Export page.

Link to this section常见问题解答#

Link to this section如何使用自定义数据集训练 YOLO26 语义分割模型?#

要使用自定义数据集训练 YOLO26 语义分割模型,你需要准备 PNG 格式的掩码图像,其中每个像素值代表一个类 ID(0, 1, 2, ...),值为 255 的像素在训练过程中会被忽略。创建一个指向图像和掩码目录的数据集 YAML 文件,然后训练模型:

示例
from ultralytics import YOLO

# Load a pretrained YOLO26 semantic segmentation model
model = YOLO("yolo26n-sem.pt")

# Train the model
results = model.train(data="path/to/your_dataset.yaml", epochs=100, imgsz=512)

查看 Configuration 页面以获取更多可用参数。

Link to this section实例分割和语义分割有什么区别?#

实例分割和语义分割都是像素级任务,但有一个关键区别:

  • 语义分割 为每个像素分配一个类标签,但不区分同一类的个体对象。例如,场景中的所有汽车共享相同的类标签。
  • 实例分割 分别识别每个个体对象,为每个对象生成不同的掩码,即使它们属于同一类别。

语义分割最适合自动驾驶和土地覆盖映射等场景理解任务,而当需要计数或跟踪个体对象时,通常首选实例分割。

Link to this section我可以使用实例分割数据来训练语义分割吗?#

Yes. If your dataset uses Ultralytics YOLO polygon labels (one .txt per image), omit masks_dir from the dataset YAML and the loader will convert polygons to per-image semantic masks on the fly. For multi-class datasets (N > 1) an extra background class is appended to names automatically. For single-class datasets (N == 1) training stays at 1 class — your declared class becomes 1 in the mask and uncovered pixels become 0. See the Semantic Segmentation Dataset Guide for details.

Link to this section语义分割支持哪些数据集?#

Ultralytics YOLO26 为多个语义分割数据集提供了内置配置:

  • Cityscapes: 具有 19 个类别的城市街道场景,广泛用于自动驾驶研究。
  • ADE20K: 一个拥有 150 个类别的大规模场景解析数据集。

你也可以使用任何提供 PNG 掩码标注的自定义数据集,其中像素值对应类 ID。

Link to this section如何验证预训练的 YOLO26 语义分割模型?#

使用用于评估的数据集 YAML 验证预训练的 YOLO26 语义分割模型:

示例
from ultralytics import YOLO

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

# Validate the model
metrics = model.val(data="cityscapes.yaml")
print("Mean IoU:", metrics.miou)
print("Pixel Accuracy:", metrics.pixel_accuracy)

这些步骤将为你提供诸如平均交并比 (mIoU) 和像素准确率等验证指标,这些是评估语义分割性能的标准度量。

Link to this section如何将 YOLO26 语义分割模型导出为 ONNX 格式?#

使用 Python 或 CLI 命令将 YOLO26 语义分割模型导出为 ONNX 格式:

示例
from ultralytics import YOLO

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

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

有关导出到各种格式的更多详细信息,请参考 Export 页面。

评论