🚀 基于ResNet - 50骨干网络的可变形DETR模型
可变形DETR(Deformable Detection Transformer)模型在COCO 2017目标检测数据集(11.8万张标注图像)上进行了端到端训练。该模型由Zhu等人在论文《Deformable DETR: Deformable Transformers for End-to-End Object Detection》中提出,并首次在此仓库发布。
声明:发布可变形DETR的团队并未为此模型撰写模型卡片,此模型卡片由Hugging Face团队编写。
🚀 快速开始
你可以使用该原始模型进行目标检测。前往模型中心查看所有可用的可变形DETR模型。
✨ 主要特性
- 端到端训练:在COCO 2017目标检测数据集上进行端到端训练,简化了目标检测流程。
- 基于Transformer架构:采用编码器 - 解码器的Transformer架构,结合卷积骨干网络,提升了检测性能。
- 目标查询机制:使用目标查询来检测图像中的物体,每个查询负责寻找特定的物体。
📚 详细文档
模型描述
DETR模型是一个带有卷积骨干网络的编码器 - 解码器Transformer。为了进行目标检测,在解码器输出的基础上添加了两个头部:一个用于类别标签的线性层和一个用于边界框的多层感知机(MLP)。该模型使用所谓的目标查询来检测图像中的物体,对于COCO数据集,目标查询的数量设置为100。
模型使用“二分匹配损失”进行训练:将N = 100个目标查询的预测类别和边界框与真实标注进行比较,真实标注会填充到相同的长度N(例如,如果一张图像仅包含4个物体,那么96个标注的类别将为“无物体”,边界框为“无边界框”)。使用匈牙利匹配算法在N个查询和N个标注之间创建最优的一对一映射。然后,使用标准的交叉熵损失(用于类别)和L1损失与广义IoU损失的线性组合(用于边界框)来优化模型的参数。

预期用途与限制
你可以使用该原始模型进行目标检测。目前,特征提取器和模型都支持PyTorch。
💻 使用示例
基础用法
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")
model = DeformableDetrForObjectDetection.from_pretrained("SenseTime/deformable-detr")
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}"
)
此代码的输出示例如下:
Detected cat with confidence 0.856 at location [342.19, 24.3, 640.02, 372.25]
Detected remote with confidence 0.739 at location [40.79, 72.78, 176.76, 117.25]
Detected cat with confidence 0.859 at location [16.5, 52.84, 318.25, 470.78]
📦 安装指南
文档未提及安装步骤,可参考Hugging Face的transformers库安装说明进行安装。
🔧 技术细节
训练数据
可变形DETR模型在COCO 2017目标检测数据集上进行训练,该数据集分别包含11.8万张和5000张用于训练和验证的标注图像。
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许可证。
属性 |
详情 |
模型类型 |
可变形DETR模型 |
训练数据 |
COCO 2017目标检测数据集 |
⚠️ 重要提示
发布可变形DETR的团队并未为此模型撰写模型卡片,此模型卡片由Hugging Face团队编写。
💡 使用建议
可以根据实际需求调整目标检测的阈值,以平衡检测的精度和召回率。