Views
No views yet
1from transformers import AutoModel, AutoTokenizer
2import torch
3import os
4os.environ["CUDA_VISIBLE_DEVICES"] = '0'
5model_name = 'alakxender/deepseek-ocr-3b-vrd-dhivehi-50k-sl'
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>\nFree OCR. "
13image_file = 'sl.png'
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)