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

相关推荐
集和诚JHCTECH13 小时前
BRAV-7120加持,让有毒有害气体无处遁形
大数据·人工智能·嵌入式硬件
OpenCSG13 小时前
以开源技术、跨境数据与绿色算力为支点,“开放东方社区”上线
开源
ZZH_AI项目交付13 小时前
我 Vibe Coding 了一个 iOS / Flutter 项目的 AI 代码改动检查工具
app·aigc·ai编程
机械X人13 小时前
Encoder-Decoder PLM
人工智能·深度学习
小锋java123413 小时前
天天说的 Agent,到底是啥???
人工智能
阿里云大数据AI技术13 小时前
MaxFrame 视频帧智能分析:从视频到语义向量的端到端分布式处理
人工智能·python
大模型任我行13 小时前
谷歌:大模型规划最优性超越传统算法
人工智能·语言模型·自然语言处理·论文笔记
两万五千个小时13 小时前
为什么你的 Agent 读了文件,却好像什么都没读到?
人工智能·程序员·架构
淘矿人14 小时前
从0到1:用Claude启动你的第一个项目
开发语言·人工智能·git·python·github·php·pygame
code_pgf14 小时前
Octo 算法详解-开源通用机器人策略模型技术报告
算法·机器人·开源