README.md
4.0 KB · 129 lines · markdown Raw
1 ---
2 pipeline_tag: image-text-to-text
3 language:
4 - multilingual
5 tags:
6 - deepseek
7 - vision-language
8 - ocr
9 - custom_code
10 license: apache-2.0
11 library_name: transformers
12 ---
13 <div align="center">
14 <img src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/logo.svg?raw=true" width="60%" alt="DeepSeek AI" />
15 </div>
16 <hr>
17 <div align="center">
18 <a href="https://www.deepseek.com/" target="_blank">
19 <img alt="Homepage" src="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/badge.svg?raw=true" />
20 </a>
21 <a href="https://huggingface.co/deepseek-ai/DeepSeek-OCR-2" target="_blank">
22 <img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-DeepSeek%20AI-ffc107?color=ffc107&logoColor=white" />
23 </a>
24
25 </div>
26
27 <div align="center">
28
29 <a href="https://discord.gg/Tc7c45Zzu5" target="_blank">
30 <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da" />
31 </a>
32 <a href="https://twitter.com/deepseek_ai" target="_blank">
33 <img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white" />
34 </a>
35
36 </div>
37
38
39
40 <p align="center">
41 <a href="https://github.com/deepseek-ai/DeepSeek-OCR-2"><b>🌟 Github</b></a> |
42 <a href="https://huggingface.co/deepseek-ai/DeepSeek-OCR-2"><b>📥 Model Download</b></a> |
43 <a href="https://github.com/deepseek-ai/DeepSeek-OCR-2/blob/main/DeepSeek_OCR2_paper.pdf"><b>📄 Paper Link</b></a> |
44 <a href="https://arxiv.org/abs/2601.20552"><b>📄 Arxiv Paper Link</b></a> |
45 </p>
46 <h2>
47 <p align="center">
48 <a href="">DeepSeek-OCR 2: Visual Causal Flow</a>
49 </p>
50 </h2>
51 <p align="center">
52 <img src="assets/fig1.png" style="width: 900px" align=center>
53 </p>
54 <p align="center">
55 <a href="">Explore more human-like visual encoding.</a>
56 </p>
57
58 ## Usage
59
60 Inference using Huggingface transformers on NVIDIA GPUs. Requirements tested on python 3.12.9 + CUDA11.8:
61
62 ```
63 torch==2.6.0
64 transformers==4.46.3
65 tokenizers==0.20.3
66 einops
67 addict
68 easydict
69 pip install flash-attn==2.7.3 --no-build-isolation
70 ```
71
72 ```python
73 from transformers import AutoModel, AutoTokenizer
74 import torch
75 import os
76 os.environ["CUDA_VISIBLE_DEVICES"] = '0'
77 model_name = 'deepseek-ai/DeepSeek-OCR-2'
78
79 tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
80 model = AutoModel.from_pretrained(model_name, _attn_implementation='flash_attention_2', trust_remote_code=True, use_safetensors=True)
81 model = model.eval().cuda().to(torch.bfloat16)
82
83 # prompt = "<image>\nFree OCR. "
84 prompt = "<image>\n<|grounding|>Convert the document to markdown. "
85 image_file = 'your_image.jpg'
86 output_path = 'your/output/dir'
87
88
89 res = model.infer(tokenizer, prompt=prompt, image_file=image_file, output_path = output_path, base_size = 1024, image_size = 768, crop_mode=True, save_results = True)
90 ```
91
92 ## vLLM
93
94
95 Refer to [🌟GitHub](https://github.com/deepseek-ai/DeepSeek-OCR-2/) for guidance on model inference acceleration and PDF processing, etc.<!-- -->
96
97 ## Support-Modes
98 - Dynamic resolution
99 - Default: (0-6)×768×768 + 1×1024×1024 — (0-6)×144 + 256 visual tokens ✅
100
101 ## Main Prompts
102 ```python
103 # document: <image>\n<|grounding|>Convert the document to markdown.
104 # without layouts: <image>\nFree OCR.
105 ```
106
107
108 ## Acknowledgement
109
110 We would like to thank [DeepSeek-OCR](https://github.com/deepseek-ai/DeepSeek-OCR/), [Vary](https://github.com/Ucas-HaoranWei/Vary/), [GOT-OCR2.0](https://github.com/Ucas-HaoranWei/GOT-OCR2.0/), [MinerU](https://github.com/opendatalab/MinerU), [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) for their valuable models and ideas.
111
112 We also appreciate the benchmark [OmniDocBench](https://github.com/opendatalab/OmniDocBench).
113
114
115 ## Citation
116
117 ```bibtex
118 @article{wei2025deepseek,
119 title={DeepSeek-OCR: Contexts Optical Compression},
120 author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
121 journal={arXiv preprint arXiv:2510.18234},
122 year={2025}
123 }
124 @article{wei2026deepseek,
125 title={DeepSeek-OCR 2: Visual Causal Flow},
126 author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
127 journal={arXiv preprint arXiv:2601.20552},
128 year={2026}
129 }