许可证:apache-2.0
标签:
- 目标检测
- 视觉
数据集:
- coco
示例展示:
- 图片链接:https://huggingface.co/datasets/mishig/sample_images/resolve/main/savanna.jpg
示例标题:热带草原
- 图片链接:https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg
示例标题:足球比赛
- 图片链接:https://huggingface.co/datasets/mishig/sample_images/resolve/main/airport.jpg
示例标题:机场
基于ResNet-50骨干网络的可变形DETR模型(带边界框优化与两阶段检测)
可变形DEtection TRansformer(DETR)模型,通过边界框优化和两阶段检测端到端训练于COCO 2017目标检测数据集(11.8万张标注图像)。该模型由Zhu等人在论文《可变形DETR:端到端目标检测中的可变形Transformer》中提出,并首发于此代码库。
免责声明:发布可变形DETR的团队未编写此模型卡片,本文档由Hugging Face团队撰写。
模型描述
DETR模型是一个基于卷积骨干网络的编码器-解码器Transformer结构。在解码器输出端添加了两个头部以执行目标检测:一个线性层用于分类标签预测,一个多层感知机(MLP)用于边界框回归。模型通过“对象查询”机制在图像中检测目标,每个查询专注于寻找图像中的特定对象。在COCO数据集中,对象查询数量设置为100。
训练采用“二分匹配损失”策略:将N=100个对象查询预测的类别和边界框与填充至相同长度N的真实标注进行对比(若图像仅含4个目标,其余96个标注的类别标记为“无对象”,边界框标记为“无边界框”)。匈牙利匹配算法用于建立查询与标注间的最优一对一映射关系,随后通过交叉熵损失(分类)及L1损失与广义IoU损失的线性组合(边界框)优化模型参数。

应用场景与限制
该模型可直接用于目标检测任务。访问模型库可查看所有可用的可变形DETR模型。
使用方法
使用方式如下:
from transformers import AutoImageProcessor, DeformableDetrForObjectDetection
import torch
from PIL import Image
import requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
processor = AutoImageProcessor.from_pretrained("SenseTime/deformable-detr-with-box-refine-two-stage")
model = DeformableDetrForObjectDetection.from_pretrained("SenseTime/deformable-detr-with-box-refine-two-stage")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
target_sizes = torch.tensor([image.size[::-1]])
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.7)[0]
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
box = [round(i, 2) for i in box.tolist()]
print(
f"检测到 {model.config.id2label[label.item()]},置信度 "
f"{round(score.item(), 3)},位置 {box}"
)
当前特征提取器与模型均仅支持PyTorch框架。
训练数据
可变形DETR模型训练于COCO 2017目标检测数据集,包含训练集11.8万张、验证集5千张标注图像。
BibTeX引用信息
@misc{https://doi.org/10.48550/arxiv.2010.04159,
doi = {10.48550/ARXIV.2010.04159},
url = {https://arxiv.org/abs/2010.04159},
author = {Zhu, Xizhou and Su, Weijie and Lu, Lewei and Li, Bin and Wang, Xiaogang and Dai, Jifeng},
keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Deformable DETR: Deformable Transformers for End-to-End Object Detection},
publisher = {arXiv},
year = {2020},
copyright = {arXiv.org perpetual, non-exclusive license}
}