参考:
https://huggingface.co/ucaslcl/GOT-OCR2_0
模型:
export HF_ENDPOINT=https://hf-mirror.comhuggingface-cli download --resume-download --local-dir-use-symlinks False ucaslcl/GOT-OCR2_0 --local-dir got_ocr
安装:
!pip install verovio megfile -i https://pypi.tuna.tsinghua.edu.cn/simple
使用:
from transformers import AutoModel, AutoTokenizertokenizer = AutoTokenizer.from_pretrained('/ai/got_ocr', trust_remote_code=True)
model = AutoModel.from_pretrained('/ai/got_ocr', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
model = model.eval().cuda()# input your test image
image_file = 'image1.jpg'# plain texts OCR
res = model.chat(tokenizer, image_file, ocr_type='ocr')res
# format texts OCR:
res = model.chat(tokenizer, image_file, ocr_type='format')
res
原图
结果:
在线latex查看:
https://arachnoid.com/latex/
公式render,打开html
# render the formatted OCR results:
image_file = 'image1.jpg'
res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')print(res)
image_file = 'road.png'# plain texts OCR
res = model.chat(tokenizer, image_file, ocr_type='ocr')res
原图
结果
image_file = 'simles1.jpg'
# format texts OCR:
res = model.chat(tokenizer, image_file, ocr_type='format')
res