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 小时前
山东云弈创峰:基于多模态AI的跨境供应链数字化重构
人工智能·重构
智慧景区与市集主理人2 小时前
巨有科技乡村农文旅智慧建设|适配乡村短板,打造轻量长效数字业态
人工智能·科技
甲维斯2 小时前
马斯克Grok4.5太会了!狙击GPT5.6,贴脸Opus4.8!
人工智能·ai编程
雪碧聊技术3 小时前
Badge 应用场景与落地实践指南
大数据·人工智能
ai产品老杨3 小时前
NVIDIA GPU部署AI视频分析项目实战记录
人工智能·音视频
修己xj3 小时前
告别排版噩梦:一个开源SKILL,让我彻底告别公众号排版的“噩梦”
开源
LL334455675 小时前
创业自动化平台怎么选
大数据·人工智能
OceanBase数据库官方博客5 小时前
OceanBase AI 时代,数据库的变与不变(技术解析与实践)
数据库·人工智能·oceanbase
冬奇Lab5 小时前
MCP 系列(01):MCP 是什么——为什么 Function Calling 不够
人工智能·llm·mcp
冬奇Lab5 小时前
每日一个开源项目(第154篇):Warp - 从‘好看的终端‘到 Agentic 开发环境
人工智能·rust·llm