YOLO-World结合YOLOv8和CLIP,实现快速开集目标检测,可自定义词汇表。
原文标题:YOLO-World开集目标检测,可直接上手
原文作者:数据派THU
冷月清谈:
安装过程包括安装Ultralytics库和CLIP库。可以使用pip install ultralytics安装或更新Ultralytics库,并使用pip install openai-clip安装CLIP库。
YOLO-World模型可以直接下载使用,例如yolov8s-world.pt。用户可以根据需要选择不同的预训练模型。
在推理过程中,可以不指定词汇表直接进行推理,也可以指定词汇表进行推理。指定词汇表时,CLIP会将词汇嵌入转换为文本特征向量,与图像一起进行推理。
代码示例演示了如何使用set_classes()方法设置词汇表,并进行目标检测。实验证明,YOLO-World的推理速度非常快,符合YOLO系列的特性。
怜星夜思:
2、CLIP在YOLO-World中扮演什么角色?能否替换成其他文本编码器?
3、YOLO-World的未来发展方向有哪些?
原文内容
来源:机器学习AI算法工程本文约1200字,建议阅读5分钟
本文介绍了YOLO-World开集目标检测。
2. 安装(更新)
由于YOLO-World主要包括两部分内容:YOLO-style的检测器、用于文本embedding的CLIP。因此,我们需要安装一个Ultralytics库、一个CLIP库。
# 新安装:pip install ultralytics # 已有Ultralytics,
更新:pip install -U ultralyticspip install openai-clip
from ultralytics import YOLO
if name == ‘main’:
Initialize a YOLO-World model
model = YOLO(‘yolov8/yolov8s-world.pt’) # or choose yolov8m/l-world.pt
Define custom classes
model.set_classes([“person”])
Execute prediction for specified categories on an image
results = model.predict(‘image_01.jpg’)
Show results
results[0].show()
def set_classes(self, text): """Perform a forward pass with optional profiling, visualization, and embedding extraction.""" try: import clip except ImportError: check_requirements("git+https://github.com/openai/CLIP.git") import clip
model, _ = clip.load(“ViT-B/32”)
device = next(model.parameters()).device
text_token = clip.tokenize(text).to(device)
txt_feats = model.encode_text(text_token).to(dtype=torch.float32)
txt_feats = txt_feats / txt_feats.norm(p=2, dim=-1, keepdim=True)
self.txt_feats = txt_feats.reshape(-1, len(text), txt_feats.shape[-1])
self.model[-1].nc = len(text)
运行效果:
Speed: 0.9ms preprocess, 43.5ms inference, 1.1ms postprocess per image at shape (1, 3, 448, 640)