UVDoc

提供商PaddlePaddle
分类image-to-text
许可证apache-2.0
下载量408.2K
星标1

简介

UVDoc 是由百度飞桨(PaddlePaddle)推出的文档图像理解模型,专注于将复杂的文档图片转化为结构化文本。它不同于简单的 OCR 文字识别,而是能够更好地理解文档的版式布局,尤其擅长处理包含表格、标题和正文的扫描件或照片。对于中国开发者来说,它提供了一个高性能的本地化部署方案,能够替代部分昂贵的商业文档解析 API,非常适合用于企业级知识库构建、自动化报表分析等 RAG 场景,上手门槛较低,可直接集成到飞桨生态中。

核心亮点

  • 精准识别文档版式,高效提取结构化文本
  • 深度优化表格解析,解决传统 OCR 乱序痛点
  • 基于 Apache-2.0 协议,支持灵活的商业部署
  • 完美适配飞桨生态,大幅提升 RAG 文档预处理效率

使用方法

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

model = AutoModel.from_pretrained("PaddlePaddle/UVDoc")
tokenizer = AutoTokenizer.from_pretrained("PaddlePaddle/UVDoc")

Hugging Face 下载

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

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

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download PaddlePaddle/UVDoc

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

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

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

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('PaddlePaddle/UVDoc')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/PaddlePaddle/UVDoc

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

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/PaddlePaddle/UVDoc

模型文件托管在 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('PaddlePaddle/UVDoc')
tokenizer = AutoTokenizer.from_pretrained('PaddlePaddle/UVDoc')

模型下载

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

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

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model PaddlePaddle/UVDoc

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

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model PaddlePaddle/UVDoc README.md --local_dir ./dir

更多更丰富的命令行下载选项,可参见具体文档

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('PaddlePaddle/UVDoc')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/PaddlePaddle/UVDoc.git

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

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/PaddlePaddle/UVDoc.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook 快速开发

下载并安装 ModelScope library

下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

模型加载和推理

模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'PaddlePaddle/UVDoc')

完整文档

来源: HuggingFace

---
license: apache-2.0
library_name: PaddleOCR
language:

  • en

  • zh

pipeline_tag: image-to-text
tags:
  • OCR

  • PaddlePaddle

  • PaddleOCR

  • doc_img_unwarping

---

UVDoc

Introduction

The main purpose of text image correction is to carry out geometric transformation on the image to correct the document distortion, inclination, perspective deformation and other problems in the image, so that the subsequent text recognition can be more accurate.

| Model| CER |
| --- | --- |
|UVDoc | 0.179 |

Note: Test data set: docunet benchmark data set.

Quick Start

Installation

1. PaddlePaddle

Please refer to the following commands to install PaddlePaddle using pip:

bash
# for CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/

for CUDA12.6

python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/

for CPU

python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/

For details about PaddlePaddle installation, please refer to the PaddlePaddle official website.

2. PaddleOCR

Install the latest version of the PaddleOCR inference package from PyPI:

bash
python -m pip install paddleocr

Model Usage

You can quickly experience the functionality with a single command:

bash
paddleocr text_image_unwarping --model_name UVDoc -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/SfMVKd0xnMII5KBDV6Mfz.jpeg

You can also integrate the model inference of the TextImageUnwarping module into your project. Before running the following code, please download the sample image to your local machine.

python
from paddleocr import TextImageUnwarping

model = TextImageUnwarping(model_name="UVDoc")
output = model.predict("SfMVKd0xnMII5KBDV6Mfz.jpeg", batch_size=1)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")

After running, the obtained result is as follows:

json
{'res': {'input_path': 'doc_test.jpg', 'page_index': None, 'doctr_img': '...'}}

The visualized image is as follows:

!image/jpeg

For details about usage command and descriptions of parameters, please refer to the Document.

Pipeline Usage

The ability of a single model is limited. But the pipeline consists of several models can provide more capacity to resolve difficult problems in real-world scenarios.

#### PP-StructureV3

Layout analysis is a technique used to extract structured information from document images. PP-StructureV3 includes the following six modules:

  • Layout Detection Module

  • General OCR Sub-pipeline

  • Document Image Preprocessing Sub-pipeline (Optional)

  • Table Recognition Sub-pipeline (Optional)

  • Seal Recognition Sub-pipeline (Optional)

  • Formula Recognition Sub-pipeline (Optional)

You can quickly experience the PP-StructureV3 pipeline with a single command.

bash
paddleocr pp_structurev3 --use_doc_unwarping True -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/KP10tiSZfAjMuwZUSLtRp.png

You can experience the inference of the pipeline with just a few lines of code. Taking the PP-StructureV3 pipeline as an example:

python
from paddleocr import PPStructureV3

pipeline = PPStructureV3(use_doc_unwarping=True) # Use use_doc_unwarping to enable/disable document unwarping module
output = pipeline.predict("./KP10tiSZfAjMuwZUSLtRp.png")
for res in output:
res.print() ## Print the structured prediction output
res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format

For details about usage command and descriptions of parameters, please refer to the Document.

Links

PaddleOCR Repo

PaddleOCR Documentation