🚀 模型卡片:OWLv2
OWLv2模型(开放世界定位的缩写)是一种零样本的文本条件目标检测模型,可使用一个或多个文本查询对图像进行查询。该模型使用CLIP作为其多模态主干,结合视觉和文本特征,实现开放词汇的目标检测。
🚀 快速开始
使用Transformers库调用模型
import requests
from PIL import Image
import numpy as np
import torch
from transformers import AutoProcessor, Owlv2ForObjectDetection
from transformers.utils.constants import OPENAI_CLIP_MEAN, OPENAI_CLIP_STD
processor = AutoProcessor.from_pretrained("google/owlv2-base-patch16")
model = Owlv2ForObjectDetection.from_pretrained("google/owlv2-base-patch16")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
texts = [["a photo of a cat", "a photo of a dog"]]
inputs = processor(text=texts, images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
def get_preprocessed_image(pixel_values):
pixel_values = pixel_values.squeeze().numpy()
unnormalized_image = (pixel_values * np.array(OPENAI_CLIP_STD)[:, None, None]) + np.array(OPENAI_CLIP_MEAN)[:, None, None]
unnormalized_image = (unnormalized_image * 255).astype(np.uint8)
unnormalized_image = np.moveaxis(unnormalized_image, 0, -1)
unnormalized_image = Image.fromarray(unnormalized_image)
return unnormalized_image
unnormalized_image = get_preprocessed_image(inputs.pixel_values)
target_sizes = torch.Tensor([unnormalized_image.size[::-1]])
results = processor.post_process_object_detection(
outputs=outputs, threshold=0.2, target_sizes=target_sizes
)
i = 0
text = texts[i]
boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
for box, score, label in zip(boxes, scores, labels):
box = [round(i, 2) for i in box.tolist()]
print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
✨ 主要特性
- 零样本检测:能够使用文本查询进行零样本目标检测,无需针对特定类别进行训练。
- 开放词汇检测:通过使用文本模型获取的类名嵌入,实现开放词汇的分类。
- 多模态骨干:使用CLIP作为多模态骨干,结合视觉和文本特征。
📦 模型详情
模型背景
OWLv2模型(开放世界定位的缩写)由Matthias Minderer、Alexey Gritsenko和Neil Houlsby在论文Scaling Open-Vocabulary Object Detection中提出。与OWL - ViT类似,OWLv2是一种零样本的文本条件目标检测模型,可使用一个或多个文本查询对图像进行查询。
模型日期
2023年6月
模型类型
该模型使用CLIP作为主干,其中图像编码器采用ViT - B/16 Transformer架构,文本编码器采用掩码自注意力Transformer。这些编码器通过对比损失进行训练,以最大化(图像,文本)对的相似度。CLIP主干从头开始训练,并与边界框和类别预测头一起在目标检测任务上进行微调。
相关文档
📚 模型使用
预期用途
本模型旨在作为研究成果供研究社区使用。我们希望该模型能帮助研究人员更好地理解和探索零样本、文本条件的目标检测。此外,我们也期望它能用于跨学科研究,探讨此类模型的潜在影响,特别是在那些通常需要识别训练期间标签不可用的对象的领域。
主要预期用户
这些模型的主要预期用户是人工智能研究人员。我们主要设想研究人员将使用该模型来更好地理解计算机视觉模型的鲁棒性、泛化能力以及其他特性、偏差和限制。
🔧 数据
模型的CLIP主干在公开可用的图像 - 字幕数据上进行训练。这是通过抓取一些网站并结合常用的现有图像数据集(如YFCC100M)来完成的。大部分数据来自互联网抓取,这意味着数据更能代表与互联网连接最紧密的人群和社会。OWL - ViT的预测头与CLIP主干一起在公开可用的目标检测数据集(如COCO和OpenImages)上进行微调。
BibTeX引用
@misc{minderer2023scaling,
title={Scaling Open-Vocabulary Object Detection},
author={Matthias Minderer and Alexey Gritsenko and Neil Houlsby},
year={2023},
eprint={2306.09683},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
📄 许可证
本模型使用Apache - 2.0许可证。