DeepSeek-OCR 2: 视觉因果流

使用方法

基于Huggingface transformers库在NVIDIA GPU上进行推理。测试环境要求为python 3.12.9 + CUDA11.8:

复制代码
torch==2.6.0
transformers==4.46.3
tokenizers==0.20.3
einops
addict 
easydict
pip install flash-attn==2.7.3 --no-build-isolation
python 复制代码
from transformers import AutoModel, AutoTokenizer
import torch
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
model_name = 'deepseek-ai/DeepSeek-OCR-2'

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(model_name, _attn_implementation='flash_attention_2', trust_remote_code=True, use_safetensors=True)
model = model.eval().cuda().to(torch.bfloat16)

# prompt = "<image>\nFree OCR. "
prompt = "<image>\n<|grounding|>Convert the document to markdown. "
image_file = 'your_image.jpg'
output_path = 'your/output/dir'


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)

vLLM

参考 🌟GitHub 获取模型推理加速和PDF处理等指南。

支持模式

  • 动态分辨率
    • 默认:(0-6)×768×768 + 1×1024×1024 --- (0-6)×144 + 256 视觉令牌 ✅

主要提示词

python 复制代码
# document: <image>\n<|grounding|>Convert the document to markdown.
# without layouts: <image>\nFree OCR.

致谢

我们感谢 DeepSeek-OCRVaryGOT-OCR2.0MinerUPaddleOCR 提供的宝贵模型和思路。

同时感谢基准测试集 OmniDocBench

相关推荐
因吹斯汀2 分钟前
基于 Pi,我居然自己搞了一个好用的 AI Agent 桌面工作台
aigc·openai·ai编程
樊小肆3 分钟前
DeepSeeker-Code源码导读05-计划模式与子Agent
人工智能·agent
办公室马主任3 分钟前
乐图数字化打通哪几个环节?从车间数据到经营决策的数据链路设计
大数据·人工智能·系统架构·制造
delishcomcn6 分钟前
数字孪生+AI预测:热烫膜分切机迈向“黑灯工厂”的关键路径
大数据·人工智能
ITresearchGuest6 分钟前
高级前端开发职业规划(2026—2035)
人工智能
皮皮虾❀7 分钟前
典铭云赛(FDE服务模式)开通钉钉AI功能全攻略:版本选择与配置指南
人工智能·钉钉
Raas10010 分钟前
MAI Gateway(魔芋企业级AI网关):企业AI网关的合规审计与调用留痕设计
大数据·人工智能·gateway·企业·api网关·mai gateway·企业级网关
桃西西呀15 分钟前
DeepSeek Harness 到底值不值得你上?我把它的内核扒了一遍
人工智能
pillowss16 分钟前
如何去除视频背景:5 种可靠的方法
人工智能·音视频
无凭17 分钟前
字节跳动 DeerFlow:Agent Harness 怎么让大模型主动向用户提问?
人工智能·python