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

相关推荐
薛定谔的猫19821 小时前
二十一、基于 Hugging Face Transformers 实现中文情感分析情感分析
人工智能·自然语言处理·大模型 训练 调优
发哥来了2 小时前
《AI视频生成技术原理剖析及金管道·图生视频的应用实践》
人工智能
数智联AI团队2 小时前
AI搜索引领开源大模型新浪潮,技术创新重塑信息检索未来格局
人工智能·开源
不懒不懒2 小时前
【线性 VS 逻辑回归:一篇讲透两种核心回归模型】
人工智能·机器学习
冰西瓜6002 小时前
从项目入手机器学习——(四)特征工程(简单特征探索)
人工智能·机器学习
Ryan老房2 小时前
未来已来-AI标注工具的下一个10年
人工智能·yolo·目标检测·ai
丝斯20113 小时前
AI学习笔记整理(66)——多模态大模型MOE-LLAVA
人工智能·笔记·学习
小鸡吃米…3 小时前
机器学习中的代价函数
人工智能·python·机器学习
chatexcel4 小时前
元空AI+Clawdbot:7×24 AI办公智能体新形态详解(长期上下文/自动化任务/工具粘合)
运维·人工智能·自动化