GOT OCR2 0
简介
核心亮点
- 全场景覆盖,支持公式、图表及多语言识别
- 通用架构,无需针对特定文档类型进行微调
- 高精度还原,有效解决复杂排版解析难题
- Apache-2.0 协议,对开发者非常友好
使用方法
# 安装 Hugging Face transformers
pip install transformers torch
# 使用 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 目录为例)
huggingface-cli download stepfun-ai/GOT-OCR2_0 config.json --local-dir ./dir
SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('stepfun-ai/GOT-OCR2_0')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://huggingface.co/stepfun-ai/GOT-OCR2_0
如果您希望跳过 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
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 目录为例)
modelscope download --model stepfun-ai/GOT-OCR2_0 README.md --local_dir ./dir
SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('stepfun-ai/GOT-OCR2_0')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://www.modelscope.cn/stepfun-ai/GOT-OCR2_0.git
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/stepfun-ai/GOT-OCR2_0.git
ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。
Notebook 快速开发
下载并安装 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')
完整文档
---
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
Usage
Inference using Huggingface transformers on NVIDIA GPUs. Requirements tested on python 3.10:torch==2.0.1
torchvision==0.15.2
transformers==4.37.2
tiktoken==0.6.0
verovio==4.3.1
accelerate==0.28.0from 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:
Citation
If you find our work helpful, please consider citing our papers 📝 and liking this project ❤️!
@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}
}