许可协议:apache-2.0
标签:
数据集:
示例展示:
- 图片地址: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")
model = DeformableDetrForObjectDetection.from_pretrained("SenseTime/deformable-detr-with-box-refine")
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框架。
训练数据
模型在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}
}