模型:
facebook/deformable-detr-detic
任务:
许可:
可变形目标检测Transformer(DETR)是在LVIS上训练的(包括1203个类别)。它在Zhou等人的论文 Detecting Twenty-thousand Classes using Image-level Supervision 中介绍,并于 this repository 首次发布。
该模型对应于原始存储库中发布的“Detic_DeformDETR_R50_4x”检查点。
声明:发布Detic的团队未为此模型编写模型卡片,因此此模型卡片由Hugging Face团队编写。
DETR模型是一个带有卷积骨干的编码器-解码器Transformer。在解码器输出的顶部添加了两个头,用于执行目标检测:用于类别标签的线性层和用于边界框的MLP(多层感知机)。模型使用所谓的对象查询在图像中检测对象。每个对象查询在图像中寻找特定的对象。对于COCO,对象查询的数量设置为100。
该模型使用“二部匹配损失”进行训练:将每个N = 100个对象查询的预测类别+边界框与地面实况注释进行比较,将其填充到相同长度的N(因此,如果图像仅包含4个对象,则96个注释只会有一个“无对象”作为类别和一个“没有边界框”作为边界框)。使用匈牙利匹配算法在这N个查询和这N个注释之间创建最优的一对一映射。接下来,使用标准的交叉熵(用于类别)和L1和广义IoU损失的线性组合(用于边界框)来优化模型的参数。
您可以使用原始模型进行目标检测。查看 model hub 以查找所有可用的可变形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("facebook/deformable-detr-detic")
model = DeformableDetrForObjectDetection.from_pretrained("facebook/deformable-detr-detic")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
# convert outputs (bounding boxes and class logits) to COCO API
# let's only keep detections with score > 0.7
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上实现了32.5的box mAP和26.2的mAP(罕见类别)。
@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}
}