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

相关推荐
阿祖zu几秒前
别再优化 RAG 了,适配 Agent 的 LLM Wiki 知识库理念
前端·后端·aigc
墨风如雪22 分钟前
AI 火了,人人都想开源,GitHub 没你想的那么复杂
aigc
leeyi1 小时前
Document 组件:把文件喂给 AI 之前,必须先做这三步
aigc·agent·ai编程
道友可好2 小时前
让 AI 自己验收,等于让学生自己批卷
前端·人工智能·后端
美团技术团队2 小时前
美团海报生成 AIGC 技术创新与实践
人工智能
冬哥聊AI2 小时前
放弃 Spring AI?这 3 个开源框架,才是让 SpringBoot 玩转 AI Agent 的正解
人工智能
小爷毛毛_卓寿杰2 小时前
当 max_tokens=1 遇上 reasoning 模型:从 Xagent 一次“测试连接“按钮的失败说起
人工智能
92year2 小时前
MCP 协议最大改版:去掉了 Session,你的 Server 要改 6 个地方
aigc
用户5191495848452 小时前
Flex QR Code Generator 漏洞利用工具 CVE-2025-10041
人工智能·aigc