GOT OCR2 0

提供商stepfun-ai
分类ocr
许可证apache-2.0
下载量616.2K
星标120

简介

GOT-OCR2.0 是由阶跃星辰(Stepfun)推出的通用 OCR 模型,旨在打破传统 OCR 仅能识别文字的局限。它不仅能精准提取文档文字,还能处理复杂的数学公式、化学方程式以及图表中的结构化数据。对于开发者而言,该模型最大的价值在于其“通用性”,无需针对不同场景(如票据、论文、截图)分别部署多个专项模型,极大地降低了视觉识别任务的链路复杂度,非常适合需要将非结构化图像快速转化为可编辑文本的 AI 应用场景。

核心亮点

  • 全场景覆盖,支持公式、图表及多语言识别
  • 通用架构,无需针对特定文档类型进行微调
  • 高精度还原,有效解决复杂排版解析难题
  • Apache-2.0 协议,对开发者非常友好

使用方法

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

model = AutoModel.from_pretrained("stepfun-ai/GOT-OCR2_0")
tokenizer = AutoTokenizer.from_pretrained("stepfun-ai/GOT-OCR2_0")

Hugging Face 下载

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

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

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download stepfun-ai/GOT-OCR2_0

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

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

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

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('stepfun-ai/GOT-OCR2_0')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/stepfun-ai/GOT-OCR2_0

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

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/stepfun-ai/GOT-OCR2_0

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

模型下载

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

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

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model stepfun-ai/GOT-OCR2_0

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

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

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

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('stepfun-ai/GOT-OCR2_0')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/stepfun-ai/GOT-OCR2_0.git

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

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/stepfun-ai/GOT-OCR2_0.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', 'stepfun-ai/GOT-OCR2_0')

完整文档

来源: HuggingFace

---
pipeline_tag: image-text-to-text
language:

  • multilingual

tags:
  • got

  • vision-language

  • ocr2.0

  • custom_code

license: apache-2.0
---

<h1>General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model
</h1>

🔋Online Demo | 🌟GitHub | 📜Paper</a>

Haoran Wei*, Chenglong Liu*, Jinyue Chen, Jia Wang, Lingyu Kong, Yanming Xu, Zheng Ge, Liang Zhao, Jianjian Sun, Yuang Peng, Chunrui Han, Xiangyu Zhang

!image/jpeg

Usage

Inference using Huggingface transformers on NVIDIA GPUs. Requirements tested on python 3.10:
code
torch==2.0.1
torchvision==0.15.2
transformers==4.37.2
tiktoken==0.6.0
verovio==4.3.1
accelerate==0.28.0
python
from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
model = model.eval().cuda()

input your test image

image_file = 'xxx.jpg'

plain texts OCR

res = model.chat(tokenizer, image_file, ocr_type='ocr')

format texts OCR:

res = model.chat(tokenizer, image_file, ocr_type='format')

fine-grained OCR:

res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')

res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')

res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')

res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')

multi-crop OCR:

res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')

res = model.chat_crop(tokenizer, image_file, ocr_type='format')

render the formatted OCR results:

res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')

print(res)


More details about 'ocr_type', 'ocr_box', 'ocr_color', and 'render' can be found at our GitHub.
Our training codes are available at our GitHub.

More Multimodal Projects

👏 Welcome to explore more multimodal projects of our team:

Vary | Fox | OneChart

Citation

If you find our work helpful, please consider citing our papers 📝 and liking this project ❤️!

bib
@article{wei2024general,
  title={General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model},
  author={Wei, Haoran and Liu, Chenglong and Chen, Jinyue and Wang, Jia and Kong, Lingyu and Xu, Yanming and Ge, Zheng and Zhao, Liang and Sun, Jianjian and Peng, Yuang and others},
  journal={arXiv preprint arXiv:2409.01704},
  year={2024}
}
@article{liu2024focus,
  title={Focus Anywhere for Fine-grained Multi-page Document Understanding},
  author={Liu, Chenglong and Wei, Haoran and Chen, Jinyue and Kong, Lingyu and Ge, Zheng and Zhu, Zining and Zhao, Liang and Sun, Jianjian and Han, Chunrui and Zhang, Xiangyu},
  journal={arXiv preprint arXiv:2405.14295},
  year={2024}
}
@article{wei2023vary,
  title={Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models},
  author={Wei, Haoran and Kong, Lingyu and Chen, Jinyue and Zhao, Liang and Ge, Zheng and Yang, Jinrong and Sun, Jianjian and Han, Chunrui and Zhang, Xiangyu},
  journal={arXiv preprint arXiv:2312.06109},
  year={2023}
}