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'
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# infer(self, tokenizer, prompt='', image_file='', output_path = ' ', base_size = 1024, image_size = 640, crop_mode = True, test_compress = False, save_results = False):
17
18# Tiny: base_size = 512, image_size = 512, crop_mode = False
19# Small: base_size = 640, image_size = 640, crop_mode = False
20# Base: base_size = 1024, image_size = 1024, crop_mode = False
21# Large: base_size = 1280, image_size = 1280, crop_mode = False
22
23# Gundam: base_size = 1024, image_size = 640, crop_mode = True
24
25res = model.infer(tokenizer, prompt=prompt, image_file=image_file, output_path = output_path, base_size = 1024, image_size = 640, crop_mode=True, save_results = True, test_compress = True)![]() | ![]() |
![]() | ![]() |