🚀 YOLOS (超小尺寸) 模型
YOLOS 模型在 COCO 2017 目标检测数据集(11.8 万张带标注图像)上进行了微调。该模型由 Fang 等人在论文 You Only Look at One Sequence: Rethinking Transformer in Vision through Object Detection 中提出,并首次在 此代码库 发布。
声明:发布 YOLOS 的团队并未为此模型撰写模型卡片,此模型卡片由 Hugging Face 团队编写。
🚀 快速开始
你可以使用该原始模型进行目标检测。访问 模型中心 查看所有可用的 YOLOS 模型。
✨ 主要特性
YOLOS 是一个使用 DETR 损失函数训练的视觉变换器(ViT)。尽管其结构简单,但基础尺寸的 YOLOS 模型在 COCO 2017 验证集上能够达到 42 的平均精度(AP),与 DETR 以及诸如 Faster R - CNN 等更复杂的框架表现相当。
该模型使用“二分匹配损失”进行训练:将 N = 100 个目标查询的预测类别和边界框与真实标注进行比较,真实标注会填充到相同的长度 N(因此,如果一张图像仅包含 4 个目标,那么 96 个标注的类别将为“无目标”,边界框为“无边界框”)。使用匈牙利匹配算法在 N 个查询和 N 个标注之间创建最优的一对一映射。接下来,使用标准的交叉熵损失(用于类别)和 L1 损失与广义交并比(IoU)损失的线性组合(用于边界框)来优化模型的参数。
💻 使用示例
基础用法
from transformers import YolosImageProcessor, YolosForObjectDetection
from PIL import Image
import torch
import requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
inputs = image_processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
bboxes = outputs.pred_boxes
target_sizes = torch.tensor([image.size[::-1]])
results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
box = [round(i, 2) for i in box.tolist()]
print(
f"Detected {model.config.id2label[label.item()]} with confidence "
f"{round(score.item(), 3)} at location {box}"
)
目前,特征提取器和模型均支持 PyTorch。
📚 详细文档
训练数据
YOLOS 模型在 ImageNet - 1k 上进行了预训练,并在 COCO 2017 目标检测 数据集上进行了微调。该数据集分别包含 11.8 万张和 5000 张用于训练和验证的带标注图像。
训练过程
该模型在 ImageNet - 1k 上预训练了 300 个轮次,并在 COCO 上微调了 300 个轮次。
评估结果
该模型在 COCO 2017 验证集上的平均精度(AP)达到了 28.7。有关评估结果的更多详细信息,请参考原论文。
BibTeX 引用和引用信息
@article{DBLP:journals/corr/abs-2106-00666,
author = {Yuxin Fang and
Bencheng Liao and
Xinggang Wang and
Jiemin Fang and
Jiyang Qi and
Rui Wu and
Jianwei Niu and
Wenyu Liu},
title = {You Only Look at One Sequence: Rethinking Transformer in Vision through
Object Detection},
journal = {CoRR},
volume = {abs/2106.00666},
year = {2021},
url = {https://arxiv.org/abs/2106.00666},
eprinttype = {arXiv},
eprint = {2106.00666},
timestamp = {Fri, 29 Apr 2022 19:49:16 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2106-00666.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
📄 许可证
本项目采用 Apache - 2.0 许可证。
📦 模型信息
属性 |
详情 |
模型类型 |
目标检测、视觉 |
训练数据 |
ImageNet - 1k、COCO 2017 目标检测 |
📋 示例展示