Views
No views yet

torch==2.6.0
transformers==4.46.3
tokenizers==0.20.3
einops
addict
easydict
pip install flash-attn==2.7.3 --no-build-isolation1from transformers import AutoModel, AutoTokenizer
2import torch
3import os
4os.environ["CUDA_VISIBLE_DEVICES"] = '0'
5model_name = 'deepseek-ai/DeepSeek-OCR-2'
6
7tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
8model = AutoModel.from_pretrained(model_name, _attn_implementation='flash_attention_2', trust_remote_code=True, use_safetensors=True)
9model = model.eval().cuda().to(torch.bfloat16)
10
11# prompt = "<image>\nFree OCR. "
12prompt = "<image>\n<|grounding|>Convert the document to markdown. "
13image_file = 'your_image.jpg'
14output_path = 'your/output/dir'
15
16
17res = 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)1# document: <image>\n<|grounding|>Convert the document to markdown.
2# without layouts: <image>\nFree OCR.1@article{wei2025deepseek,
2 title={DeepSeek-OCR: Contexts Optical Compression},
3 author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
4 journal={arXiv preprint arXiv:2510.18234},
5 year={2025}
6}
7@article{wei2026deepseek,
8 title={DeepSeek-OCR 2: Visual Causal Flow},
9 author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
10 journal={arXiv preprint arXiv:2601.20552},
11 year={2026}
12}