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-OCR、Vary、GOT-OCR2.0、MinerU、PaddleOCR 提供的宝贵模型和思路。

同时感谢基准测试集 OmniDocBench。

相关推荐
挖掘狂人1 分钟前
2026 年,为什么一线团队开始从 MCP 撤回 CLI?
人工智能·agent·mcp
问天_观心2 分钟前
模型微调学习(二)
开发语言·人工智能·学习·语言模型·github
LaughingZhu2 分钟前
Product Hunt 热榜 2026-10-20:Beam.win、Figma Specs、readywhen
人工智能·深度学习·神经网络·搜索引擎·百度
吠品5 分钟前
Flutter 工程配本地 Maven 引 AAR,仓库声明为啥不生效
c语言·人工智能·算法
Frag0ut9 分钟前
Chrome DevTools 2026进阶:AI辅助调试与性能诊断原生实战指南
前端·人工智能·chrome devtools·ai调试·lighthouse性能分析·内存泄漏诊断·css容器查询
林伽一12 分钟前
GPU 调度栈开源与框架层精炼:AI 基础设施的两个新落点|2026年10月20日
人工智能·科技·安全·ai·开源
武子康13 分钟前
从预约改期看 Agent 工具粒度:把不变量留在权威服务
人工智能·后端·agent
miofly15 分钟前
GitHub 今日推荐|security-audit-skill:让编码代理自己审计漏洞还互相验证
javascript·开源·github
Wanda121418 分钟前
机器人与机电一体化3D数字孪生机器-Day5
人工智能·unity·游戏引擎·数字孪生
frankzch20 分钟前
HybridAgent 拆解:在潜空间想,动手时才出字
人工智能·深度学习·语言模型