detr doc table detection

提供商TahaDouaji
分类object-detection
许可证apache-2.0
下载量154.9K
星标0

简介

detr-doc-table-detection 是一款基于 DETR 架构的文档表格检测模型,专门用于从复杂的 PDF 或扫描文档图像中精准定位表格区域。与传统的基于规则或启发式方法不同,它将表格检测视为目标检测任务,能有效处理表格边框缺失、布局不规则等痛点。对于需要构建 RAG 知识库或自动化报表分析的开发者来说,它是文档解析流水线(Document Parsing Pipeline)中至关重要的一环,通常在 OCR 识别之前使用,用于确定表格的坐标范围,从而实现结构化数据的精准提取。

核心亮点

  • 基于 DETR 架构,表格定位精度高且鲁棒
  • 支持无边框或复杂布局表格的精准识别
  • 适配文档数字化与 RAG 知识库预处理
  • Apache-2.0 协议,商业部署无压力

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("TahaDouaji/detr-doc-table-detection")
tokenizer = AutoTokenizer.from_pretrained("TahaDouaji/detr-doc-table-detection")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download TahaDouaji/detr-doc-table-detection

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download TahaDouaji/detr-doc-table-detection config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('TahaDouaji/detr-doc-table-detection')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/TahaDouaji/detr-doc-table-detection

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/TahaDouaji/detr-doc-table-detection

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('TahaDouaji/detr-doc-table-detection')
tokenizer = AutoTokenizer.from_pretrained('TahaDouaji/detr-doc-table-detection')

完整文档

来源: HuggingFace

---
tags:

  • object-detection

  • '- vision'

  • onnx

license: apache-2.0
base_model: facebook/detr-resnet-50
datasets:
  • MohamedExperio/ICDAR2019

---

Model Card for detr-doc-table-detection

Model Details

detr-doc-table-detection is a model trained to detect both Bordered and Borderless tables in documents, based on facebook/detr-resnet-50.
  • Developed by: Taha Douaji
  • Shared by [Optional]: Taha Douaji
  • Model type: Object Detection
  • Language(s) (NLP): More information needed
  • License: More information needed
  • Resources for more information:
- Model Demo Space - Associated Paper

Uses

Direct Use

This model can be used for the task of object detection.

Out-of-Scope Use

The model should not be used to intentionally create hostile or alienating environments for people.

Bias, Risks, and Limitations

Significant research has explored bias and fairness issues with language models (see, e.g., Sheng et al. (2021) and Bender et al. (2021)). Predictions generated by the model may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups.

Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.

Training Details

Training Data

The model was trained on ICDAR2019 Table Dataset

Environmental Impact

Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).

Citation

BibTeX:


bibtex
@article{DBLP:journals/corr/abs-2005-12872,
author = {Nicolas Carion and
Francisco Massa and
Gabriel Synnaeve and
Nicolas Usunier and
Alexander Kirillov and
Sergey Zagoruyko},
title = {End-to-End Object Detection with Transformers},
journal = {CoRR},
volume = {abs/2005.12872},
year = {2020},
url = {https://arxiv.org/abs/2005.12872},
archivePrefix = {arXiv},
eprint = {2005.12872},
timestamp = {Thu, 28 May 2020 17:38:09 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2005-12872.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}

Model Card Authors [optional]

Taha Douaji in collaboration with Ezi Ozoani and the Hugging Face team

Model Card Contact

More information needed

How to Get Started with the Model

Use the code below to get started with the model.
python
from transformers import DetrImageProcessor, DetrForObjectDetection
import torch
from PIL import Image
import requests

image = Image.open("IMAGE_PATH")

processor = DetrImageProcessor.from_pretrained("TahaDouaji/detr-doc-table-detection")
model = DetrForObjectDetection.from_pretrained("TahaDouaji/detr-doc-table-detection")

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.9

target_sizes = torch.tensor([image.size[::-1]]) results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[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}"
)