🚀 基于DocLayNet训练的可变形DETR模型
本模型为基于DocLayNet(包含11个类别、8万页标注数据)训练的可变形检测变换器(Deformable DEtection TRansformer,简称Deformable DETR)。
你可以在无服务器的 Aryn分区服务 中使用该模型。点击 此处 开启使用之旅。
🚀 快速开始
你可以使用此原始模型进行目标检测。可在 模型中心 查找所有可用的可变形DETR模型。
💻 使用示例
基础用法
from transformers import AutoImageProcessor, DeformableDetrForObjectDetection
import torch
from PIL import Image
import requests
url = "https://huggingface.co/Aryn/deformable-detr-DocLayNet/resolve/main/examples/doclaynet_example_1.png"
image = Image.open(requests.get(url, stream=True).raw)
processor = AutoImageProcessor.from_pretrained("Aryn/deformable-detr-DocLayNet")
model = DeformableDetrForObjectDetection.from_pretrained("Aryn/deformable-detr-DocLayNet")
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}"
)
✨ 主要特性
DETR模型是一个带有卷积骨干网络的编解码器变换器。为了进行目标检测,在解码器输出的基础上添加了两个头部:一个用于类别标签的线性层和一个用于边界框的多层感知器(MLP)。该模型使用所谓的目标查询来检测图像中的目标。每个目标查询在图像中寻找特定的目标。对于COCO数据集,目标查询的数量设置为100。
模型使用“二分匹配损失”进行训练:将N = 100个目标查询的预测类别和边界框与真实标注进行比较,标注会填充到相同的长度N(因此,如果一张图像仅包含4个目标,96个标注的类别将为“无目标”,边界框为“无边界框”)。使用匈牙利匹配算法在N个查询和N个标注之间创建最优的一对一映射。接下来,使用标准的交叉熵(用于类别)和L1损失与广义交并比损失的线性组合(用于边界框)来优化模型的参数。

📚 详细文档
评估结果
该模型在DocLayNet数据集上的边界框平均精度均值(box mAP)达到了57.1。
训练数据
可变形DETR模型基于DocLayNet数据集进行训练。该数据集由Pfitzmann等人在论文 DocLayNet: A Large Human-Annotated Dataset for Document-Layout Analysis 中提出,并首次在 此仓库 中发布。
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许可证。