GOT OCR2 0

Providerstepfun-ai
Categoryocr
Licenseapache-2.0
Downloads616.2K
Stars120

Overview

GOT OCR2.0 is a specialized vision-language model designed to bridge the gap between raw image data and structured text extraction. Unlike traditional OCR engines that rely on rigid pipeline architectures, this model treats document understanding as a generative task, allowing it to handle complex layouts, handwritten notes, and multi-lingual documents with higher spatial awareness. For developers, this means a streamlined integration process where visual parsing and semantic understanding happen in a single pass. It is particularly effective for automating data entry from non-standardized forms and digitizing legacy archives where traditional rule-based systems typically fail. Released under the Apache-2.0 license, it offers the flexibility needed for commercial deployment and custom fine-tuning on domain-specific datasets.

Highlights

  • Generative architecture for superior complex layout parsing
  • Unified vision-language processing reduces integration pipeline complexity
  • Strong support for multi-lingual and handwritten text extraction
  • Apache-2.0 license ensures flexible commercial deployment
  • High spatial accuracy for structured document digitizing

Usage

Install
# Install Hugging Face transformers
pip install transformers torch
SDK Usage
# Load model with 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 Download

We recommend downloading the model via the Hugging Face CLI or Hub SDK.

Guidance:Before downloading, install huggingface_hub with:

Guidance
pip install -U huggingface_hub

CLI Download

Download the full repository

Download the full repository
huggingface-cli download stepfun-ai/GOT-OCR2_0

Download a single file to a local folder (e.g. config.json into ./dir)

Download a single file to a local folder (e.g. config.json into ./dir)
huggingface-cli download stepfun-ai/GOT-OCR2_0 config.json --local-dir ./dir

See the official docs for more CLI options

SDK Download

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

Git Download

Make sure git-lfs is installed first

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

To skip LFS large-file downloads, use:

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

Model files are hosted on the Hugging Face Hub — download directly via HF CLI / SDK / Git, not through this site.

PyTorch / Transformers Usage

Install Transformers

Install Transformers
pip install -U transformers torch

Load the model and run inference

Load the model and run inference
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('stepfun-ai/GOT-OCR2_0')
tokenizer = AutoTokenizer.from_pretrained('stepfun-ai/GOT-OCR2_0')

Model Download

We recommend downloading the model via the ModelScope CLI or SDK.

Guidance:Before downloading, install ModelScope with:

Guidance
pip install modelscope

CLI Download

Download the full repository

Download the full repository
modelscope download --model stepfun-ai/GOT-OCR2_0

Download a single file to a local folder (e.g. README.md into ./dir)

Download a single file to a local folder (e.g. README.md into ./dir)
modelscope download --model stepfun-ai/GOT-OCR2_0 README.md --local_dir ./dir

See the docs for more CLI options

SDK Download

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

Git Download

Make sure git-lfs is installed first

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

To skip LFS large-file downloads, use:

Skip LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/stepfun-ai/GOT-OCR2_0.git

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

Notebook Quickstart

Install the ModelScope library

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

Load the model and run inference

Load the model and run inference
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'stepfun-ai/GOT-OCR2_0')

Full Documentation

来源: 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}
}
Join our Telegram