跳至内容

YOLOE:实时看到任何东西

导言

YOLOE 提示选项

YOLOE(Real-Time Seeing Anything)是零镜头、可提示YOLO 模型的新进展,专为开放词汇检测和分割而设计。与以往仅限于固定类别的YOLO 模型不同,YOLOE 使用文本、图像或内部词汇提示,可对任何对象类别进行实时检测。YOLOE 以YOLO 为基础,受YOLO启发,实现了最先进的零镜头性能,对速度和准确性的影响最小。



观看: 如何使用 YOLOE 和Ultralytics Python 软件包:开放式词汇表与实时洞察 🚀

与早期的YOLO 模型相比,YOLOE 显著提高了效率和准确性。在 LVIS 上,它比YOLO 提高了+3.5 AP,同时只使用了三分之一的训练资源,推理速度提高了 1.4 倍。在 COCO 上进行微调后,YOLOE-v8-YOLOv8 比YOLOv8 提高了0.1 mAP,使用的训练时间减少了4 倍。这证明了 YOLOE 在准确性、效率和多功能性方面的卓越平衡。下文将探讨 YOLOE 的架构、基准比较以及与 Ultralytics框架的集成。

建筑概览

YOLOE 建筑事务所

YOLOE 保留了标准的YOLO 结构--用于特征提取的卷积骨干(如 CSP-Darknet),用于多尺度融合的颈部(如 PAN-FPN),以及无锚、解耦检测(与YOLO11 相同),可独立预测对象性、类别和方框。YOLOE 引入了三个新模块,实现了开放词汇检测:

  • 可重新参数化的区域-文本对齐(RepRTA):通过一个小型辅助网络完善文本嵌入(例如来自 CLIP),从而支持文本提示检测。在推理时,该网络被折叠到主模型中,确保零开销。因此,YOLOE 可以检测任意文本标签对象(如未见过的 "红绿灯"),而不会产生运行时惩罚。

  • 语义激活视觉提示编码器(SAVPE):通过轻量级嵌入分支实现视觉提示检测。在给定参考图像的情况下,SAVPE 对语义和激活特征进行编码,使模型能够检测视觉上相似的物体--这种一次性检测能力对于徽标或特定部件非常有用。

  • 懒惰区域提示对比 (LRPC):无提示模式下,YOLOE 使用在大型词汇表(来自 LVIS 和 Objects365 的 1200 多个类别)上训练的内部嵌入执行开放集识别。在没有外部提示或编码器的情况下,YOLOE 通过嵌入相似性查找来识别对象,从而在推理时高效地处理大型标签空间。

此外,YOLOE 还通过扩展检测头和掩码预测分支(类似于 YOLACT 或YOLOv8)集成了实时实例分割功能,从而将开销降至最低。

最重要的是,YOLOE 的开放世界模块在用作常规封闭集YOLO 时不会带来推理成本。训练后,YOLOE 的参数可以重新参数化为标准的YOLO 头,并保持相同的 FLOP 和速度(例如,与YOLO 的匹配)。 YOLO11完全匹配)。

可用型号、支持的任务和运行模式

本节详细介绍了可用的模型及其特定的预训练权重、支持的任务以及与各种运行模式(如推理验证训练导出)的兼容性,支持的模式用 ✅ 表示,不支持的模式用 ❌ 表示。

文本/视频提示模式

型号 预训练重量 支持的任务 推论 验证 培训 出口
YOLOE-11S yoloe-11s-seg.pt 实例分割
YOLOE-11M yoloe-11m-seg.pt 实例分割
YOLOE-11L yoloe-11l-seg.pt 实例分割
YOLOE-v8S yoloe-v8s-seg.pt 实例分割
YOLOE-v8M yoloe-v8m-seg.pt 实例分割
YOLOE-v8L yoloe-v8l-seg.pt 实例分割

及时免费模型

型号 预训练重量 支持的任务 推论 验证 培训 出口
YOLOE-11S-PF yoloe-11s-seg-pf.pt 实例分割
YOLOE-11M-PF yoloe-11m-seg-pf.pt 实例分割
YOLOE-11L-PF yoloe-11l-seg-pf.pt 实例分割
YOLOE-v8S-PF yoloe-v8s-seg-pf.pt 实例分割
YOLOE-v8M-PF yoloe-v8m-seg-pf.pt 实例分割
YOLOE-v8L-PF yoloe-v8l-seg-pf.pt 实例分割

使用示例

YOLOE 模型很容易集成到您的Python 应用程序中。Ultralytics 提供用户友好的Python APICLI 命令,以简化开发过程。

列车使用情况

自定义数据集微调

示例

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEPESegTrainer

model = YOLOE("yoloe-11s-seg.pt")

model.train(
    data="coco128-seg.yaml",
    epochs=80,
    close_mosaic=10,
    batch=128,
    optimizer="AdamW",
    lr0=1e-3,
    warmup_bias_lr=0.0,
    weight_decay=0.025,
    momentum=0.9,
    workers=4,
    device="0",
    trainer=YOLOEPESegTrainer,
)
from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEPESegTrainer

model = YOLOE("yoloe-11s-seg.pt")
head_index = len(model.model.model) - 1
freeze = [str(f) for f in range(0, head_index)]
for name, child in model.model.model[-1].named_children():
    if "cv3" not in name:
        freeze.append(f"{head_index}.{name}")

freeze.extend(
    [
        f"{head_index}.cv3.0.0",
        f"{head_index}.cv3.0.1",
        f"{head_index}.cv3.1.0",
        f"{head_index}.cv3.1.1",
        f"{head_index}.cv3.2.0",
        f"{head_index}.cv3.2.1",
    ]
)

model.train(
    data="coco128-seg.yaml",
    epochs=2,
    close_mosaic=0,
    batch=16,
    optimizer="AdamW",
    lr0=1e-3,
    warmup_bias_lr=0.0,
    weight_decay=0.025,
    momentum=0.9,
    workers=4,
    device="0",
    trainer=YOLOEPESegTrainer,
    freeze=freeze,
)

预测使用情况

YOLOE supports both text-based and visual prompting. Using prompts is straightforward—just pass them through the predict 方法,如下图所示:

示例

Text prompts allow you to specify the classes that you wish to detect through textual descriptions. The following code shows how you can use YOLOE to detect people and buses in an image:

from ultralytics import YOLOE

# Initialize a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")  # or select yoloe-11s/m-seg.pt for different sizes

# Set text prompt to detect person and bus. You only need to do this once after you load the model.
names = ["person", "bus"]
model.set_classes(names, model.get_text_pe(names))

# Run detection on the given image
results = model.predict("path/to/image.jpg")

# Show results
results[0].show()

Visual prompts allow you to guide the model by showing it visual examples of the target classes, rather than describing them in text.

"(《世界人权宣言》) visual_prompts argument takes a dictionary with two keys: bboxescls. Each bounding box in bboxes should tightly enclose an example of the object you want the model to detect, and the corresponding entry in cls specifies the class label for that box. This pairing tells the model, "This is what class X looks like—now find more like it."

Class IDs (cls) in visual_prompts are used to associate each bounding box with a specific category within your prompt. They aren't fixed labels, but temporary identifiers you assign to each example. The only requirement is that class IDs must be sequential, starting from 0. This helps the model correctly associate each box with its respective class.

You can provide visual prompts directly within the same image you want to run inference on. For example:

import numpy as np

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEVPSegPredictor

# Initialize a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")

# Define visual prompts using bounding boxes and their corresponding class IDs.
# Each box highlights an example of the object you want the model to detect.
visual_prompts = dict(
    bboxes=np.array(
        [
            [221.52, 405.8, 344.98, 857.54],  # Box enclosing person
            [120, 425, 160, 445],  # Box enclosing glasses
        ],
    ),
    cls=np.array(
        [
            0,  # ID to be assigned for person
            1,  # ID to be assigned for glassses
        ]
    ),
)

# Run inference on an image, using the provided visual prompts as guidance
results = model.predict(
    "ultralytics/assets/bus.jpg",
    visual_prompts=visual_prompts,
    predictor=YOLOEVPSegPredictor,
)

# Show results
results[0].show()

Or you can provide examples from a separate reference image using the refer_image argument. In that case, the bboxesclsvisual_prompts should describe objects in the reference image, not the target image you're making predictions on:

备注

如果 source is a video or stream, the model automatically uses the first frame as the refer_image. This means your visual_prompts are applied to that initial frame to help the model understand what to look for in the rest of the video. Alternatively, you can explicitly pass any specific frame as the refer_image to control which visual examples the model uses as reference.

import numpy as np

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEVPSegPredictor

# Initialize a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")

# Define visual prompts based on a separate reference image
visual_prompts = dict(
    bboxes=np.array([[221.52, 405.8, 344.98, 857.54]]),  # Box enclosing person
    cls=np.array([0]),  # ID to be assigned for person
)

# Run prediction on a different image, using reference image to guide what to look for
results = model.predict(
    "ultralytics/assets/zidane.jpg",  # Target image for detection
    refer_image="ultralytics/assets/bus.jpg",  # Reference image used to get visual prompts
    visual_prompts=visual_prompts,
    predictor=YOLOEVPSegPredictor,
)

# Show results
results[0].show()

You can also pass multiple target images to run prediction on:

import numpy as np

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEVPSegPredictor

# Initialize a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")

# Define visual prompts using bounding boxes and their corresponding class IDs.
# Each box highlights an example of the object you want the model to detect.
visual_prompts = dict(
    bboxes=[
        np.array(
            [
                [221.52, 405.8, 344.98, 857.54],  # Box enclosing person
                [120, 425, 160, 445],  # Box enclosing glasses
            ],
        ),
        np.array([[150, 200, 1150, 700]]),
    ],
    cls=[
        np.array(
            [
                0,  # ID to be assigned for person
                1,  # ID to be assigned for glasses
            ]
        ),
        np.array([0]),
    ],
)

# Run inference on multiple image, using the provided visual prompts as guidance
results = model.predict(
    ["ultralytics/assets/bus.jpg", "ultralytics/assets/zidane.jpg"],
    visual_prompts=visual_prompts,
    predictor=YOLOEVPSegPredictor,
)

# Show results
results[0].show()

YOLOE also includes prompt-free variants that come with a built-in vocabulary. These models don't require any prompts and work like traditional YOLO models. Instead of relying on user-provided labels or visual examples, they detect objects from a predefined list of 4,585 classes based on the tag set used by the Recognize Anything Model Plus (RAM++).

from ultralytics import YOLOE

# Initialize a YOLOE model
model = YOLOE("yoloe-11l-seg-pf.pt")

# Run prediction. No prompts required.
results = model.predict("path/to/image.jpg")

# Show results
results[0].show()

阀门使用

示例

from ultralytics import YOLOE

# Create a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")  # or select yoloe-11s/m-seg.pt for different sizes

# Conduct model validation on the COCO128-seg example dataset
metrics = model.val(data="coco128-seg.yaml")

默认情况下,它会使用提供的数据集提取每个类别的视觉嵌入。

from ultralytics import YOLOE

# Create a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")  # or select yoloe-11s/m-seg.pt for different sizes

# Conduct model validation on the COCO128-seg example dataset
metrics = model.val(data="coco128-seg.yaml", load_vp=True)

或者,我们也可以使用另一个数据集作为参考数据集来提取每个类别的视觉嵌入。 请注意,该参考数据集的类别应与所提供的数据集完全相同。

from ultralytics import YOLOE

# Create a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")  # or select yoloe-11s/m-seg.pt for different sizes

# Conduct model validation on the COCO128-seg example dataset
metrics = model.val(data="coco128-seg.yaml", load_vp=True, refer_data="coco.yaml")
from ultralytics import YOLOE

# Create a YOLOE model
model = YOLOE("yoloe-11l-seg.pt")  # or select yoloe-11s/m-seg.pt for different sizes

# Conduct model validation on the COCO128-seg example dataset
metrics = model.val(data="coco128-seg.yaml")

数据集的模型验证简化如下:

火车官方模型

准备数据集

备注

训练官方 YOLOE 模型需要对训练数据进行分段注释,下面是 官方团队提供的脚本 可将数据集转换为段注释,由 SAM2.1 模型.或直接下载所提供的 Processed Segment Annotations 见官方小组提供的下表。

  • 列车数据
  • Val 数据
数据集 类型 注释文件
LVIS minival 检测 minival.txt

从零开始启动培训

备注

Visual Prompt 模型进行微调。 Text Prompt 型号

示例

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOESegTrainerFromScratch

data = dict(
    train=dict(
        yolo_data=["Objects365.yaml"],
        grounding_data=[
            dict(
                img_path="../datasets/flickr/full_images/",
                json_file="../datasets/flickr/annotations/final_flickr_separateGT_train_segm.json",
            ),
            dict(
                img_path="../datasets/mixed_grounding/gqa/images",
                json_file="../datasets/mixed_grounding/annotations/final_mixed_train_no_coco_segm.json",
            ),
        ],
    ),
    val=dict(yolo_data=["lvis.yaml"]),
)

model = YOLOE("yoloe-11l-seg.yaml")
model.train(
    data=data,
    batch=128,
    epochs=30,
    close_mosaic=2,
    optimizer="AdamW",
    lr0=2e-3,
    warmup_bias_lr=0.0,
    weight_decay=0.025,
    momentum=0.9,
    workers=4,
    trainer=YOLOESegTrainerFromScratch,
    device="0,1,2,3,4,5,6,7",
)

因为只有 SAVPE 模块需要在训练过程中更新。 将训练有素的文本提示模型转换为检测模型,以较低的训练成本采用检测流水线。 请注意,这一步是可选的,您也可以直接从分割开始。

import torch

from ultralytics import YOLOE

det_model = YOLOE("yoloe-11l.yaml")
state = torch.load("yoloe-11l-seg.pt")
det_model.load(state["model"])
det_model.save("yoloe-11l-seg-det.pt")

开始训练

from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEVPTrainer

data = dict(
    train=dict(
        yolo_data=["Objects365.yaml"],
        grounding_data=[
            dict(
                img_path="../datasets/flickr/full_images/",
                json_file="../datasets/flickr/annotations/final_flickr_separateGT_train_segm.json",
            ),
            dict(
                img_path="../datasets/mixed_grounding/gqa/images",
                json_file="../datasets/mixed_grounding/annotations/final_mixed_train_no_coco_segm.json",
            ),
        ],
    ),
    val=dict(yolo_data=["lvis.yaml"]),
)

model = YOLOE("yoloe-11l-seg.pt")
# replace to yoloe-11l-seg-det.pt if converted to detection model
# model = YOLOE("yoloe-11l-seg-det.pt")

# freeze every layer except of the savpe module.
head_index = len(model.model.model) - 1
freeze = list(range(0, head_index))
for name, child in model.model.model[-1].named_children():
    if "savpe" not in name:
        freeze.append(f"{head_index}.{name}")

model.train(
    data=data,
    batch=128,
    epochs=2,
    close_mosaic=2,
    optimizer="AdamW",
    lr0=16e-3,
    warmup_bias_lr=0.0,
    weight_decay=0.025,
    momentum=0.9,
    workers=4,
    trainer=YOLOEVPTrainer,
    device="0,1,2,3,4,5,6,7",
    freeze=freeze,
)

训练后转换回分割模型。只有在训练前将分割模型转换为检测模型时才需要。

from copy import deepcopy

from ultralytics import YOLOE

model = YOLOE("yoloe-11l-seg.yaml")
model.load("yoloe-11l-seg.pt")

vp_model = YOLOE("yoloe-11l-vp.pt")
model.model.model[-1].savpe = deepcopy(vp_model.model.model[-1].savpe)
model.eval()
model.save("yoloe-11l-seg.pt")

与视觉提示训练类似,无提示模型在训练过程中只需更新专门的提示嵌入。 将训练有素的文本提示模型转换为检测模型,以较低的训练成本采用检测流水线。 请注意,这一步是可选的,您也可以直接从分割开始。

import torch

from ultralytics import YOLOE

det_model = YOLOE("yoloe-11l.yaml")
state = torch.load("yoloe-11l-seg.pt")
det_model.load(state["model"])
det_model.save("yoloe-11l-seg-det.pt")
开始训练
from ultralytics import YOLOE

data = dict(
    train=dict(
        yolo_data=["Objects365.yaml"],
        grounding_data=[
            dict(
                img_path="../datasets/flickr/full_images/",
                json_file="../datasets/flickr/annotations/final_flickr_separateGT_train_segm.json",
            ),
            dict(
                img_path="../datasets/mixed_grounding/gqa/images",
                json_file="../datasets/mixed_grounding/annotations/final_mixed_train_no_coco_segm.json",
            ),
        ],
    ),
    val=dict(yolo_data=["lvis.yaml"]),
)

model = YOLOE("yoloe-11l-seg.pt")
# replace to yoloe-11l-seg-det.pt if converted to detection model
# model = YOLOE("yoloe-11l-seg-det.pt")

# freeze layers.
head_index = len(model.model.model) - 1
freeze = [str(f) for f in range(0, head_index)]
for name, child in model.model.model[-1].named_children():
    if "cv3" not in name:
        freeze.append(f"{head_index}.{name}")

freeze.extend(
    [
        f"{head_index}.cv3.0.0",
        f"{head_index}.cv3.0.1",
        f"{head_index}.cv3.1.0",
        f"{head_index}.cv3.1.1",
        f"{head_index}.cv3.2.0",
        f"{head_index}.cv3.2.1",
    ]
)

model.train(
    data=data,
    batch=128,
    epochs=1,
    close_mosaic=1,
    optimizer="AdamW",
    lr0=2e-3,
    warmup_bias_lr=0.0,
    weight_decay=0.025,
    momentum=0.9,
    workers=4,
    trainer=YOLOEPEFreeTrainer,
    device="0,1,2,3,4,5,6,7",
    freeze=freeze,
    single_cls=True,  # this is needed
)

训练后转换回分割模型。只有在训练前将分割模型转换为检测模型时才需要。

from copy import deepcopy

from ultralytics import YOLOE

model = YOLOE("yoloe-11l-seg.pt")
model.eval()

pf_model = YOLOE("yoloe-11l-seg-pf.pt")
names = ["object"]
tpe = model.get_text_pe(names)
model.set_classes(names, tpe)
model.model.model[-1].fuse(model.model.pe)

model.model.model[-1].cv3[0][2] = deepcopy(pf_model.model.model[-1].cv3[0][2]).requires_grad_(True)
model.model.model[-1].cv3[1][2] = deepcopy(pf_model.model.model[-1].cv3[1][2]).requires_grad_(True)
model.model.model[-1].cv3[2][2] = deepcopy(pf_model.model.model[-1].cv3[2][2]).requires_grad_(True)
del model.model.pe
model.save("yoloe-11l-seg-pf.pt")

YOLOE 性能比较

在 COCO 等标准基准测试中,YOLOE 的精确度达到或超过封闭式YOLO 模型,而速度或模型大小不受影响。下表将 YOLOE-L(基于YOLO11 建立)与相应的 YOLOv8和YOLO11 模型的比较:

模型 COCOmAP50-95 推理速度(T4) 参数 GFLOPs (640px)
YOLOv8(闭合套件) 52.9% 9.06 毫秒(110 FPS) 43.7 M 165.2 B
YOLO11(闭合套管) 53.5% 6.2 毫秒(130 FPS) 26.2 M 86.9 B
YOLOE-L(开放式手术室) 52.6% 6.2 毫秒(130 FPS) 26.2 M 86.9B†

YOLO11 和 YOLOE-L 具有相同的架构(YOLO11YOLO11 禁用了提示模块),因此推理速度相同,GFLOPs 估计值也相似。

YOLOE-L 实现了52.6% 的 mAP,超过了YOLOv8(52.9%),但参数却减少了约40%(26M 对 43.7M)。它处理 640×640 图像的时间为6.2 毫秒(161 FPS),而YOLOv8 为9.06 毫秒(110 FPS),这凸显了YOLO11 的效率。最重要的是,YOLOE 的开放式词汇模块产生推理成本,体现了"没有免费午餐 "的设计理念。

在零拍摄和转移任务方面,YOLOE 表现出色:在 LVIS 上,YOLOE-small 比YOLO 提高了+3.5 AP,使用的训练资源减少了 3 倍。将 YOLOE-L 从 LVIS 微调到 COCO 所需的训练时间也比YOLOv8 少 4 倍,这突出表明了它的效率和适应性。YOLOE 进一步保持了YOLO 的标志性速度,在 T4GPU 上实现了300+ FPS,通过CoreML 在 iPhone 12 上实现了~64 FPS,非常适合边缘和移动部署。

备注

基准条件:YOLOE 的结果来自在 Objects365、GoldG 和 LVIS 上预先训练的模型,然后在 COCO 上进行微调或评估。与YOLOv8 相比,YOLOE 在 mAP 方面的微弱优势来自广泛的预训练。如果没有这种开放式虚拟实验室训练,YOLOE 可以与类似大小的YOLO 模型相媲美,这充分证明了它的 SOTA 准确性和开放世界灵活性,而不会降低性能。

与以前型号的比较

与之前的YOLO 模型和开放词汇检测器相比,YOLOE 有着显著的进步:

  • YOLOE vsYOLOv5:
    YOLOv5YOLOv5 在速度和准确度之间取得了很好的平衡,但需要对新类别进行重新训练,并且使用基于锚的头部。相比之下,YOLOE不需要锚点,而且可以动态检测新的类别。YOLOE 在YOLOv8 的改进基础上实现了更高的准确率(52.6%,而YOLOv5 在 COCO 上的 mAP 为 50%),并且与YOLOv5 不同,它集成了实例分割功能。

  • YOLOE vsYOLOv8:
    YOLOE 扩展 YOLOv8的重新设计架构,实现了相似或更高的准确率(使用 ~26M 参数时,mAP 为 52.6%使用 ~44M 参数时, YOLOv8 为 52.9%)。由于加强了预训练,它大大缩短了训练时间。与YOLOv8 的封闭式设计不同,YOLOv8 的关键进步在于其开放世界功能,可通过提示检测未见物体(如"小鸟滑板车"或"和平符号")。

  • YOLOE vsYOLO11:
    YOLO11在YOLOv8 的基础上提高了效率,减少了参数(减少约 22%)。YOLOE 直接继承了这些改进,推理速度和参数数量(约 2600 万个参数)与YOLO11 相当,同时增加了开放词汇检测和分段功能。在封闭场景中,YOLOE 与YOLO11 相当,但关键是增加了检测未见类别的适应性,在不影响速度的情况下实现了YOLO11 + 开放世界的功能

  • YOLOE 与以前的开放词汇检测器的对比:
    早期的开放式词汇模型(GLIP、OWL-ViT、YOLO)严重依赖视觉语言转换器,导致推理速度缓慢。YOLOE 在零拍准确率上超过了这些模型(例如,与YOLO 相比,零拍准确率提高了 3.5 ),同时在大幅减少训练资源的情况下,运行速度提高了 1.4 倍。与基于变压器的方法(如 GLIP)相比,YOLOE 的推理速度快了几个数量级,有效地缩小了开放集检测的准确率-效率差距。

总之,YOLOE 保持了YOLO 久负盛名的速度和效率,在准确性上超越了前代产品,集成了细分功能,并引入了强大的开放世界检测功能,使其具有独特的多功能性和实用性。

使用案例和应用

YOLOE 的开放式词汇检测和分词功能使其应用范围超越了传统的固定类模型:

  • 开放世界物体检测:
    非常适合机器人等动态场景,机器人可通过提示识别以前未见过的物体,安防系统也可快速适应新的威胁(如危险物品),无需重新训练。

  • 快速检测和单次检测:
    通过视觉提示 (SAVPE),YOLOE 可从单个参考图像中快速学习新对象,非常适合工业检测(即时识别部件或缺陷)或定制监控,只需最少的设置即可实现视觉搜索。

  • 大词汇量和长尾识别:
    YOLOE 拥有超过 1000 个类别的词汇量,在生物多样性监测(检测稀有物种)、博物馆藏品零售库存电子商务等任务中表现出色,无需进行大量的每类训练即可可靠地识别许多类别。

  • 交互式检测和分割:
    YOLOE 支持实时交互式应用,如可搜索的视频/图像检索增强现实(AR)和直观的图像编辑,由自然输入(文本或视觉提示)驱动。用户可以使用分割掩码动态地精确隔离、识别或编辑对象。

  • 自动数据标注和引导:
    YOLOE 通过提供初始边界框和分割注释来促进数据集的快速创建,大大减少了人工标注的工作量。在分析大型媒体集合时尤为重要,它可以自动识别存在的对象,帮助更快地建立专门的模型。

  • 任意物体的分割:
    通过提示将分割功能扩展到任意物体--尤其适用于医学成像显微镜卫星图像分析,无需专门的预训练模型即可自动识别并精确分割结构。与 SAM不同的是,YOLOE 可同时自动识别和分割对象,从而为内容创建场景理解等任务提供帮助。

在所有这些使用案例中,YOLOE 的核心优势在于通用性,它为动态场景中的检测、识别和分割提供了统一的模型。其效率可确保在资源有限的设备上实现实时性能,是机器人、自动驾驶、国防等领域的理想选择。

提示

根据您的需求选择 YOLOE 模式:

  • 封闭设置模式:用于固定类任务(最大速度和精度)。
  • 提示模式:通过文本或视觉提示快速添加新对象。
  • 无提示开放设置模式:跨多个类别的一般检测(编目和发现的理想选择)。

通常情况下,将各种模式结合起来--例如在无提示的探索模式之后进行有针对性的提示--可以充分发挥 YOLOE 的潜力。

训练和推理

YOLOE 与Ultralytics Python APICLI与其他YOLO 模型YOLOv8、YOLO)类似。下面是快速入门的方法:

使用 YOLOE 进行训练和推理

from ultralytics import YOLO

# Load pre-trained YOLOE model and train on custom data
model = YOLO("yoloe-11s-seg.pt")
model.train(data="path/to/data.yaml", epochs=50, imgsz=640)

# Run inference using text prompts ("person", "bus")
model.set_classes(["person", "bus"])
results = model.predict(source="test_images/street.jpg")
results[0].save()  # save annotated output

在这里,YOLOE 的默认行为类似于标准检测器,但通过指定类别 (set_classes).结果包含边界框、遮罩和标签。

# Training YOLOE on custom dataset
yolo train model=yoloe-11s-seg.pt data=path/to/data.yaml epochs=50 imgsz=640

# Inference with text prompts
yolo predict model=yoloe-11s-seg.pt source="test_images/street.jpg" classes="person,bus"

CLI 提示 (classes)对 YOLOE 的引导类似于Python 的 set_classes.可视化提示(基于图像的查询)目前需要Python API。

其他支持的任务

  • 验证: 使用 model.val()yolo val.
  • 出口: 出口 YOLOE 型号 (model.export())到ONNX、TensorRT 等,方便部署。
  • 跟踪: YOLOE 支持物体跟踪 (yolo track) 集成后,可用于跟踪视频中的提示类。

备注

YOLOE 自动包括 分割掩码 在推理结果中 (results[0].masks),简化了物体提取或测量等像素精度任务,而无需单独的模型。

入门

按照以下步骤快速设置 YOLOE 与Ultralytics :

  1. 安装 安装或更新Ultralytics 软件包:

    pip install -U ultralytics
    
  2. 下载 YOLOE Weights: 预训练的 YOLOE 模型(例如 YOLOE-v8-S/L、YOLOE-11 变体)可从 YOLOE GitHub 发布的版本中获取。只需下载所需的 .pt 文件加载到Ultralytics YOLO 类中。

  3. 硬件要求

    • 推论:推荐使用GPU NVIDIA ,≥4-8GB VRAM)。小型模型可在边缘 GPU(如Jetson)或较低分辨率的 CPU 上高效运行。
    • 训练:在自定义数据上对 YOLOE 进行微调通常只需要一个GPU。作者使用的大量开放词汇预训练(LVIS/Objects365)需要大量计算(8× RTX 4090 GPU)。
  4. 配置: YOLOE 配置使用标准的Ultralytics YAML 文件。默认配置(例如 yoloe-11s-seg.yaml)通常就足够了,但你也可以根据需要修改骨干、类别或图像大小。

  5. 运行 YOLOE

    • 快速推理 (免提):
      yolo predict model=yoloe-11s-seg-pf.pt source="image.jpg"
      
    • 提示检测(文本提示示例):

      from ultralytics import YOLO
      
      model = YOLO("yoloe-11s-seg.pt")
      names = ["bowl", "apple"]
      model.set_classes(names, model.get_text_pe(names))
      results = model.predict("kitchen.jpg")
      results[0].save()
      
  6. 集成技巧

    • 班级名称:默认 YOLOE 输出使用 LVIS 类别;使用 set_classes() 来指定您自己的标签。
    • 速度:除非使用提示,否则 YOLOE 没有任何开销。文字提示的影响最小,视觉提示的影响稍大。
    • 批量推理:直接支持 (model.predict([img1, img2])).有关特定图像的提示,请单独运行图像。

Ultralytics 文档提供了更多资源。YOLOE 可让您在熟悉的YOLO 生态系统中轻松探索强大的开放世界功能。

提示

专业提示: 要最大限度地提高 YOLOE 的零射击准确性,请根据提供的检查点进行微调,而不是从头开始训练。使用与常见训练标签(请参阅 LVIS 类别)一致的提示词来提高检测准确性。

引用和致谢

如果 YOLOE 为您的研究或项目做出了贡献,请引用清华大学 王敖、刘力豪、陈辉、林子嘉、韩军工和丁桂光的原始论文:

@misc{wang2025yoloerealtimeseeing,
      title={YOLOE: Real-Time Seeing Anything},
      author={Ao Wang and Lihao Liu and Hui Chen and Zijia Lin and Jungong Han and Guiguang Ding},
      year={2025},
      eprint={2503.07465},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2503.07465},
}

如需进一步阅读,可在arXiv 上查阅 YOLOE 论文原文。该项目的源代码和其他资源可通过GitHub 存储库访问。

常见问题

YOLOE 与YOLO 有何不同?

虽然 YOLOE 和YOLO都能进行开放词汇检测,但 YOLOE 有几个优势。与YOLO 相比,YOLOE 在 LVIS 上的准确率提高了 +3.5 倍,同时使用的训练资源减少了 3 倍,运行速度提高了 1.4 倍。YOLOE 还支持三种提示模式(文本、视觉和内部词汇),而YOLO 主要侧重于文本提示。此外,YOLOE 还具有内置实例分割功能,可为检测到的对象提供像素精确的掩码,而无需额外的开销。

我可以将 YOLOE 作为普通YOLO 模型使用吗?

是的,YOLOE 的功能与标准YOLO 型号完全相同,而且不会降低性能。在封闭设置模式(无提示)下使用时,YOLOE 的开放式词汇模块被重新参数化为标准检测头,因此速度和准确性与同等的YOLO11 型号完全相同。这使得 YOLOE 具有极大的通用性--您可以将其作为传统检测器使用,以获得最高速度,然后只在需要时才切换到开放词汇模式。

YOLOE 可以使用哪些类型的提示?

YOLOE 支持三种类型的提示:

  1. 文本提示:使用自然语言指定对象类别(如 "人"、"交通灯"、"小鸟滑板车)
  2. 视觉提示:提供要检测物体的参考图像
  3. 内部词汇:使用 YOLOE 内置的 1200 多个类别的词汇,无需外部提示

这种灵活性使 YOLOE 能够适应各种情况,而无需重新训练模型,因此特别适用于检测要求经常变化的动态环境。

YOLOE 如何处理实例分割?

YOLOE 通过扩展带有掩码预测分支的检测头,将实例分割直接集成到其架构中。这种方法与YOLOv8 类似,但适用于任何已提示的对象类别。分割掩码会自动包含在推理结果中,并可通过以下方式访问 results[0].masks.这种统一的方法无需单独的检测和分割模型,从而简化了需要精确到像素的对象边界的应用的工作流程。

YOLOE 如何处理自定义提示的推理?

YOLO 类似,YOLOE 支持 "先提示后检测 "策略,利用离线词汇提高效率。自定义提示(如标题或特定对象类别)被预先编码并存储为离线词汇嵌入。这种方法可简化检测过程,无需重新训练。您可以在模型中动态设置这些提示,使其适合特定的检测任务:

from ultralytics import YOLO

# Initialize a YOLOE model
model = YOLO("yoloe-11s-seg.pt")

# Define custom classes
names = ["person", "bus"]
model.set_classes(names, model.get_text_pe(names))

# Execute prediction on an image
results = model.predict("path/to/image.jpg")

# Show results
results[0].show()


📅创建于 1 个月前 ✏️已更新 0 天前

评论