Link to this sectionYOLO-World 模型#
YOLO-World 模型引入了一种基于 Ultralytics YOLOv8 的先进实时开放词汇检测方法。这一创新使得模型能够根据描述性文本检测图像中的任何对象。通过在保持竞争性能的同时显著降低计算需求,YOLO-World 成为了适用于众多基于视觉的应用的通用工具。
Watch: YOLO World training workflow on custom dataset

Link to this section概述#
YOLO-World 解决了传统开放词汇检测模型所面临的挑战,这些模型通常依赖于需要大量计算资源的笨重的 Transformer 模型。这些模型对预定义对象类别的依赖也限制了它们在动态场景中的实用性。YOLO-World 通过采用视觉-语言建模以及在海量数据集上进行预训练,为 YOLOv8 框架注入了开放词汇检测能力,从而能够以卓越的效率在零样本场景中出色地识别各类对象。
Link to this section主要特性#
-
实时解决方案: YOLO-World 利用 CNN 的计算速度,提供了一种快速的开放词汇检测解决方案,能够满足需要即时结果的行业需求。
-
效率与性能: YOLO-World 在不牺牲性能的前提下大幅削减了计算和资源需求,提供了一种比 SAM 等模型更强大且计算成本仅为一小部分的替代方案,从而实现了实时应用。
-
离线词汇推理: YOLO-World 引入了“提示-检测”策略,采用离线词汇表来进一步提高效率。这种方法允许使用预先计算好的自定义提示(包括标题或类别)进行编码并存储为离线词汇嵌入,从而简化了检测过程。
-
基于 YOLOv8: YOLO-World 构建于 Ultralytics YOLOv8 之上,利用实时目标检测领域的最新进展,以无与伦比的精度和速度助力开放词汇检测。
-
基准卓越: YOLO-World 在标准基准测试中的速度和效率均优于现有的开放词汇检测器(包括 MDETR 和 GLIP 系列),展示了 YOLOv8 在单块 NVIDIA V100 GPU 上的卓越能力。
-
多功能应用: YOLO-World 的创新方法为众多视觉任务解锁了新的可能性,其速度较现有方法提升了几个数量级。
Link to this section可用模型、支持的任务和操作模式#
本节详细介绍了可用的模型及其特定的预训练权重、它们支持的任务,以及它们与各种运行模式(例如 推理、验证、训练 和 导出)的兼容性,其中 ✅ 表示支持的模式,❌ 表示不支持的模式。
所有 YOLOv8-World 权重均直接从官方 YOLO-World 仓库迁移而来,体现了其卓越的贡献。
| 模型类型 | 预训练权重 | 支持的任务 | 推理 | 验证 | 训练 | 导出 |
|---|---|---|---|---|---|---|
| YOLOv8s-world | yolov8s-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8s-worldv2 | yolov8s-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8m-world | yolov8m-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8m-worldv2 | yolov8m-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8l-world | yolov8l-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8l-worldv2 | yolov8l-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8x-world | yolov8x-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8x-worldv2 | yolov8x-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
Link to this sectionCOCO 数据集上的零样本迁移#
| 模型类型 | mAP | mAP50 | mAP75 |
|---|---|---|---|
| yolov8s-world | 37.4 | 52.0 | 40.6 |
| yolov8s-worldv2 | 37.7 | 52.2 | 41.0 |
| yolov8m-world | 42.0 | 57.0 | 45.6 |
| yolov8m-worldv2 | 43.0 | 58.4 | 46.8 |
| yolov8l-world | 45.7 | 61.3 | 49.8 |
| yolov8l-worldv2 | 45.8 | 61.3 | 49.8 |
| yolov8x-world | 47.0 | 63.0 | 51.2 |
| yolov8x-worldv2 | 47.1 | 62.8 | 51.4 |
Link to this section使用示例#
YOLO-World 模型易于集成到你的 Python 应用中。Ultralytics 提供了用户友好的 Python API 和 CLI 命令 来简化开发流程。
Watch: YOLO-World Model Usage examples with Ultralytics | Open Vocab, Prompt-Free & others 🚀
Link to this section训练使用#
我们强烈建议使用 yolov8-worldv2 模型进行自定义训练,因为它支持确定性训练,并且易于导出为其他格式(如 onnx/tensorrt)。
目标检测 使用 train 方法非常简单,如下所示:
PyTorch 预训练的 *.pt 模型以及配置文件 *.yaml 都可以传入 YOLOWorld() 类,以便在 Python 中创建模型实例:
from ultralytics import YOLOWorld
# Load a pretrained YOLOv8s-worldv2 model
model = YOLOWorld("yolov8s-worldv2.pt")
# Train the model on the COCO8 example dataset for 100 epochs
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)
# Run inference with the YOLO-World model on the 'bus.jpg' image
results = model("path/to/bus.jpg")Link to this section预测使用#
目标检测使用 predict 方法非常简单,如下所示:
from ultralytics import YOLOWorld
# Initialize a YOLO-World model
model = YOLOWorld("yolov8s-world.pt") # or select yolov8m/l-world.pt for different sizes
# Execute inference with the YOLOv8s-world model on the specified image
results = model.predict("path/to/image.jpg")
# Show results
results[0].show()此代码片段演示了加载预训练模型并对图像进行预测的简单性。
Link to this section验证使用#
数据集上的模型验证流程如下:
from ultralytics import YOLO
# Create a YOLO-World model
model = YOLO("yolov8s-world.pt") # or select yolov8m/l-world.pt for different sizes
# Conduct model validation on the COCO8 example dataset
metrics = model.val(data="coco8.yaml")Link to this section跟踪使用#
在视频/图像上使用 YOLO-World 模型进行 目标追踪 的流程如下:
from ultralytics import YOLO
# Create a YOLO-World model
model = YOLO("yolov8s-world.pt") # or select yolov8m/l-world.pt for different sizes
# Track with a YOLO-World model on a video
results = model.track(source="path/to/video.mp4")Ultralytics 提供的 YOLO-World 模型已预配置了 COCO 数据集 的类别作为其离线词汇的一部分,从而提高了即时应用的效率。这种集成使 YOLOv8-World 模型无需额外设置或自定义,即可直接识别并预测 COCO 数据集中定义的 80 个标准类别。
Link to this section设置提示#

YOLO-World 框架允许通过自定义提示动态指定类别,使用户能够根据特定需求调整模型,无需重新训练。此功能对于将模型适应到最初不属于 训练数据 的新领域或特定任务特别有用。通过设置自定义提示,你可以引导模型的关注点指向感兴趣的对象,从而增强检测结果的相关性和 准确性。
例如,如果你的应用只需要检测“人(person)”和“公交车(bus)”对象,你可以直接指定这些类别:
from ultralytics import YOLO
# Initialize a YOLO-World model
model = YOLO("yolov8s-world.pt") # or choose yolov8m/l-world.pt
# Define custom classes
model.set_classes(["person", "bus"])
# Execute prediction for specified categories on an image
results = model.predict("path/to/image.jpg")
# Show results
results[0].show()一些用户发现,添加一个空字符串 "" 作为背景类别可以在某些场景中改善检测性能。这种行为似乎取决于场景,具体机制尚未完全明确:
model.set_classes(["person", "bus", ""])你也可以在设置自定义类别后保存模型。通过这样做,你可以创建一个专门针对你特定用例的 YOLO-World 模型版本。此过程将你的自定义类别定义直接嵌入到模型文件中,使得模型无需进一步调整即可使用你指定的类别。请按照以下步骤保存并加载你的自定义 YOLO-World 模型:
首先加载一个 YOLO-World 模型,为其设置自定义类别并保存:
from ultralytics import YOLO
# Initialize a YOLO-World model
model = YOLO("yolov8s-world.pt") # or select yolov8m/l-world.pt
# Define custom classes
model.set_classes(["person", "bus"])
# Save the model with the defined offline vocabulary
model.save("custom_yolov8s.pt")保存后,custom_yolov8s.pt 模型会像任何其他预训练的 YOLOv8 模型一样运行,但有一个关键区别:它现在经过优化,仅能检测你定义的类别。这种自定义可以显著提高你特定应用场景的检测性能和效率。
from ultralytics import YOLO
# Load your custom model
model = YOLO("custom_yolov8s.pt")
# Run inference to detect your custom classes
results = model.predict("path/to/image.jpg")
# Show results
results[0].show()Link to this section使用自定义词汇保存的优势#
- 效率:通过专注于相关对象来简化检测过程,减少计算开销并加快推理速度。
- 灵活性:允许模型轻松适应新的或小众的检测任务,无需进行大量的重新训练或数据收集。
- 简便性:消除了在运行时重复指定自定义类别的需要,简化了部署流程,使模型能够直接使用其嵌入的词汇表。
- 性能:通过将模型的注意力和资源集中在识别定义的物体上,从而增强特定类别的检测准确性。
这种方法为针对特定任务定制最先进的 目标检测 模型提供了强大的手段,使得先进的 AI 技术更易于访问并应用于更广泛的实际场景中。
Link to this section从零开始复现官方结果(实验性)#
Link to this section准备数据集#
- 训练数据
| 数据集 | 类型 | 样本 | 框 | 标注文件 |
|---|---|---|---|---|
| Objects365v1 | 检测 | 609k | 9621k | objects365_train.json |
| GQA | Grounding | 621k | 3681k | final_mixed_train_no_coco.json |
| Flickr30k | 定位 | 149k | 641k | final_flickr_separateGT_train.json |
- 验证数据
| 数据集 | 类型 | 标注文件 |
|---|---|---|
| LVIS minival | 检测 | minival.txt |
Link to this section从零开始启动训练#
WorldTrainerFromScratch 经过高度定制,允许同时在检测数据集和定位数据集上训练 YOLO-World 模型。更多详细信息请参阅 ultralytics.model.yolo.world.train_world.py。
from ultralytics import YOLOWorld
from ultralytics.models.yolo.world.train_world import WorldTrainerFromScratch
# Option 1: Use Python dictionary
data = dict(
train=dict(
yolo_data=["Objects365.yaml"],
grounding_data=[
dict(
img_path="flickr30k/images",
json_file="flickr30k/final_flickr_separateGT_train.json",
),
dict(
img_path="GQA/images",
json_file="GQA/final_mixed_train_no_coco.json",
),
],
),
val=dict(yolo_data=["lvis.yaml"]),
)
# Option 2: Use YAML file (yolo_world_data.yaml)
# train:
# yolo_data:
# - Objects365.yaml
# grounding_data:
# - img_path: flickr/full_images/
# json_file: flickr/annotations/final_flickr_separateGT_train_segm.json
# - img_path: mixed_grounding/gqa/images
# json_file: mixed_grounding/annotations/final_mixed_train_no_coco_segm.json
# val:
# yolo_data:
# - lvis.yaml
model = YOLOWorld("yolov8s-worldv2.yaml")
model.train(
data=data, # or data="yolo_world_data.yaml" if using YAML file
batch=128,
epochs=100,
trainer=WorldTrainerFromScratch,
)Link to this section引用与致谢#
我们向 Tencent AILab Computer Vision Center 在使用 YOLO-World 进行实时开放词汇目标检测方面所做的开创性工作表示感谢:
@article{cheng2024yolow,
title={YOLO-World: Real-Time Open-Vocabulary Object Detection},
author={Cheng, Tianheng and Song, Lin and Ge, Yixiao and Liu, Wenyu and Wang, Xinggang and Shan, Ying},
journal={arXiv preprint arXiv:2401.17270},
year={2024}
}如需进一步阅读,原始 YOLO-World 论文可在 arXiv 上查阅。该项目的源代码和其他资源可通过他们的 GitHub repository 获取。我们感谢他们为推进该领域发展并与社区分享宝贵见解所做出的贡献。
Link to this section常见问题解答#
Link to this section什么是 YOLO-World 模型,它是如何工作的?#
YOLO-World 模型是一种基于 Ultralytics YOLOv8 框架的先进实时目标检测方法。它擅长通过根据描述性文本识别图像中的对象来执行开放词汇检测任务。通过使用视觉语言建模并在大规模数据集上进行预训练,YOLO-World 实现了高效率和高性能,同时显著降低了计算需求,使其非常适合各行业的实时应用。
Link to this sectionYOLO-World 如何处理带有自定义提示词的推理?#
YOLO-World 支持一种“提示词后检测”策略,该策略利用离线词汇表来提高效率。自定义提示词(如标题或特定的对象类别)会被预先编码并存储为离线词汇表 embeddings。这种方法简化了检测过程,而无需重新训练。你可以根据模型动态设置这些提示词,以针对特定的检测任务进行定制,如下所示:
from ultralytics import YOLOWorld
# Initialize a YOLO-World model
model = YOLOWorld("yolov8s-world.pt")
# Define custom classes
model.set_classes(["person", "bus"])
# Execute prediction on an image
results = model.predict("path/to/image.jpg")
# Show results
results[0].show()Link to this section为什么我应该选择 YOLO-World 而不是传统的开放词汇检测模型?#
与传统的开放词汇检测模型相比,YOLO-World 具有以下几个优势:
- 实时性能: 它利用 CNN 的计算速度来提供快速、高效的检测。
- 效率和低资源需求: YOLO-World 在保持高性能的同时,显著降低了计算和资源需求。
- 可定制的提示词: 该模型支持动态提示词设置,允许用户指定自定义检测类别而无需重新训练。
- 基准测试表现出色: 在标准基准测试中,其速度和效率均优于 MDETR 和 GLIP 等其他开放词汇检测器。
Link to this section如何在我自己的数据集上训练 YOLO-World 模型?#
通过提供的 Python API 或 CLI 命令,在你自己的数据集上训练 YOLO-World 模型非常简单。以下是如何使用 Python 开始训练的方法:
from ultralytics import YOLOWorld
# Load a pretrained YOLOv8s-worldv2 model
model = YOLOWorld("yolov8s-worldv2.pt")
# Train the model on the COCO8 dataset for 100 epochs
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)或者使用 CLI:
yolo train model=yolov8s-worldv2.yaml data=coco8.yaml epochs=100 imgsz=640Link to this section有哪些可用的预训练 YOLO-World 模型及其支持的任务?#
Ultralytics 提供了多个预训练的 YOLO-World 模型,支持各种任务和操作模式:
| 模型类型 | 预训练权重 | 支持的任务 | 推理 | 验证 | 训练 | 导出 |
|---|---|---|---|---|---|---|
| YOLOv8s-world | yolov8s-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8s-worldv2 | yolov8s-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8m-world | yolov8m-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8m-worldv2 | yolov8m-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8l-world | yolov8l-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8l-worldv2 | yolov8l-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv8x-world | yolov8x-world.pt | 目标检测 | ✅ | ✅ | ✅ | ❌ |
| YOLOv8x-worldv2 | yolov8x-worldv2.pt | 目标检测 | ✅ | ✅ | ✅ | ✅ |
Link to this section如何从零开始复现 YOLO-World 的官方结果?#
要从零开始复现官方结果,你需要准备数据集并使用提供的代码启动训练。训练过程包括创建数据字典,并使用自定义训练器运行 train 方法:
from ultralytics import YOLOWorld
from ultralytics.models.yolo.world.train_world import WorldTrainerFromScratch
data = {
"train": {
"yolo_data": ["Objects365.yaml"],
"grounding_data": [
{
"img_path": "flickr30k/images",
"json_file": "flickr30k/final_flickr_separateGT_train.json",
},
{
"img_path": "GQA/images",
"json_file": "GQA/final_mixed_train_no_coco.json",
},
],
},
"val": {"yolo_data": ["lvis.yaml"]},
}
model = YOLOWorld("yolov8s-worldv2.yaml")
model.train(data=data, batch=128, epochs=100, trainer=WorldTrainerFromScratch)