🚀 可变形DETR模型(基于LVIS数据集训练)
本项目基于LVIS数据集(包含1203个类别)训练了可变形检测变换器(Deformable DETR)模型。该模型由Zhou等人在论文 Detecting Twenty-thousand Classes using Image-level Supervision 中提出,并首次在 此代码库 中发布。本模型对应于原代码库中发布的 “Box-Supervised_DeformDETR_R50_4x” 检查点。
免责声明
发布Detic的团队并未为此模型编写模型卡片,此模型卡片由Hugging Face团队编写。
🚀 快速开始
你可以使用此原始模型进行目标检测。可在 模型中心 查找所有可用的可变形DETR模型。
✨ 主要特性
- 模型架构:DETR模型是一个带有卷积骨干网络的编码器 - 解码器变换器。在解码器输出之上添加了两个头部以进行目标检测:一个用于类别标签的线性层和一个用于边界框的多层感知机(MLP)。模型使用所谓的目标查询来检测图像中的目标。每个目标查询在图像中寻找特定的目标。对于COCO数据集,目标查询的数量设置为100。
- 训练损失:模型使用 “二分匹配损失” 进行训练。将N = 100个目标查询的预测类别和边界框与真实标注进行比较,标注会填充到相同的长度N(因此,如果图像仅包含4个目标,96个标注的类别将为 “无目标”,边界框为 “无边界框”)。使用匈牙利匹配算法在N个查询和N个标注之间创建最优的一对一映射。然后,使用标准的交叉熵(用于类别)和L1与广义IoU损失的线性组合(用于边界框)来优化模型的参数。

📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
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("facebook/deformable-detr-box-supervised")
model = DeformableDetrForObjectDetection.from_pretrained("facebook/deformable-detr-box-supervised")
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"Detected {model.config.id2label[label.item()]} with confidence "
f"{round(score.item(), 3)} at location {box}"
)
📚 详细文档
评估结果
此模型在LVIS数据集上实现了31.7的边界框平均精度均值(box mAP)和21.4的稀有类平均精度均值(mAP)。
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}
}
📄 许可证
本模型使用Apache 2.0许可证。