🚀 YOLOS (tiny-sized) 模型
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)损失的线性组合(用于边界框)来优化模型的参数。
📦 安装指南
暂未提及安装相关内容,可参考 Hugging Face 上的通用安装方式来安装所需依赖库。
💻 使用示例
基础用法
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。有关评估结果的更多详细信息,请参考原始论文。
🔧 技术细节
该模型使用“二分匹配损失”进行训练,将预测结果与真实标注进行比较,并使用匈牙利匹配算法创建最优映射,再结合标准交叉熵和 L1 与广义 IoU 损失的线性组合来优化模型参数。
📄 许可证
本项目采用 Apache-2.0 许可证。
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}
}
示例展示