Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: image-text-to-text
|
| 3 |
+
library_name: transformers
|
| 4 |
+
language:
|
| 5 |
+
- multilingual
|
| 6 |
+
tags:
|
| 7 |
+
- got
|
| 8 |
+
- vision-language
|
| 9 |
+
- ocr2.0
|
| 10 |
+
- custom_code
|
| 11 |
+
license: apache-2.0
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
<h1>General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model
|
| 15 |
+
</h1>
|
| 16 |
+
|
| 17 |
+
[🔋Online Demo](https://huggingface.co/spaces/ucaslcl/GOT_online) | [🌟GitHub](https://github.com/Ucas-HaoranWei/GOT-OCR2.0/) | [📜Paper](https://arxiv.org/abs/2409.01704)</a>
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
[Haoran Wei*](https://scholar.google.com/citations?user=J4naK0MAAAAJ&hl=en), Chenglong Liu*, Jinyue Chen, Jia Wang, Lingyu Kong, Yanming Xu, [Zheng Ge](https://joker316701882.github.io/), Liang Zhao, [Jianjian Sun](https://scholar.google.com/citations?user=MVZrGkYAAAAJ&hl=en), [Yuang Peng](https://scholar.google.com.hk/citations?user=J0ko04IAAAAJ&hl=zh-CN&oi=ao), Chunrui Han, [Xiangyu Zhang](https://scholar.google.com/citations?user=yuB-cfoAAAAJ&hl=en)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+

|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
Inference using Huggingface transformers on NVIDIA GPUs. Requirements tested on python 3.10:
|
| 30 |
+
```
|
| 31 |
+
torch==2.0.1
|
| 32 |
+
torchvision==0.15.2
|
| 33 |
+
transformers==4.37.2
|
| 34 |
+
tiktoken==0.6.0
|
| 35 |
+
verovio==4.3.1
|
| 36 |
+
accelerate==0.28.0
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from transformers import AutoModel, AutoTokenizer
|
| 42 |
+
|
| 43 |
+
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
| 44 |
+
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)
|
| 45 |
+
model = model.eval().cuda()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# input your test image
|
| 49 |
+
image_file = 'xxx.jpg'
|
| 50 |
+
|
| 51 |
+
# plain texts OCR
|
| 52 |
+
res = model.chat(tokenizer, image_file, ocr_type='ocr')
|
| 53 |
+
|
| 54 |
+
# format texts OCR:
|
| 55 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format')
|
| 56 |
+
|
| 57 |
+
# fine-grained OCR:
|
| 58 |
+
# res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')
|
| 59 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')
|
| 60 |
+
# res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')
|
| 61 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')
|
| 62 |
+
|
| 63 |
+
# multi-crop OCR:
|
| 64 |
+
# res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')
|
| 65 |
+
# res = model.chat_crop(tokenizer, image_file, ocr_type='format')
|
| 66 |
+
|
| 67 |
+
# render the formatted OCR results:
|
| 68 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')
|
| 69 |
+
|
| 70 |
+
print(res)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
More details about 'ocr_type', 'ocr_box', 'ocr_color', and 'render' can be found at our GitHub.
|
| 75 |
+
Our training codes are available at our [GitHub](https://github.com/Ucas-HaoranWei/GOT-OCR2.0/).
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
## More Multimodal Projects
|
| 80 |
+
|
| 81 |
+
👏 Welcome to explore more multimodal projects of our team:
|
| 82 |
+
|
| 83 |
+
[Vary](https://github.com/Ucas-HaoranWei/Vary) | [Fox](https://github.com/ucaslcl/Fox) | [OneChart](https://github.com/LingyvKong/OneChart)
|
| 84 |
+
|
| 85 |
+
## Citation
|
| 86 |
+
|
| 87 |
+
If you find our work helpful, please consider citing our papers 📝 and liking this project ❤️!
|
| 88 |
+
|
| 89 |
+
```bib
|
| 90 |
+
@article{wei2024general,
|
| 91 |
+
title={General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model},
|
| 92 |
+
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},
|
| 93 |
+
journal={arXiv preprint arXiv:2409.01704},
|
| 94 |
+
year={2024}
|
| 95 |
+
}
|
| 96 |
+
@article{liu2024focus,
|
| 97 |
+
title={Focus Anywhere for Fine-grained Multi-page Document Understanding},
|
| 98 |
+
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},
|
| 99 |
+
journal={arXiv preprint arXiv:2405.14295},
|
| 100 |
+
year={2024}
|
| 101 |
+
}
|
| 102 |
+
@article{wei2023vary,
|
| 103 |
+
title={Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models},
|
| 104 |
+
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},
|
| 105 |
+
journal={arXiv preprint arXiv:2312.06109},
|
| 106 |
+
year={2023}
|
| 107 |
+
}
|
| 108 |
+
```
|