周红伟 DeepSeek-OCR v2技术原理和架构,部署案例实操

DeepSeek-OCR 发布于25年10月,而这次DeepSeek-OCR 2发布仅隔了三个月。这会不会是DeepSeek V4发布前上的前菜呢?让我们一起尝尝鲜吧。

DeepSeek发布全新DeepSeek-OCR 2模型,采用创新的DeepEncoder V2方法,让AI能够根据图像的含义动态重排图像的各个部分,而不再只是机械地从左到右扫描。这种方式模拟了人类在观看场景时所遵循的逻辑流程。最终,该模型在处理布局复杂的图片时,表现优于传统的视觉-语言模型,实现了更智能、更具因果推理能力的视觉理解。

github地址:https://github.com/deepseek-ai/DeepSeek-OCR-2

DeepSeek-OCR 2: Visual Causal Flow

Explore more human-like visual encoding.

Contents

Install

Our environment is cuda11.8+torch2.6.0.

  1. Clone this repository and navigate to the DeepSeek-OCR-2 folder
复制代码
git clone https://github.com/deepseek-ai/DeepSeek-OCR-2.git
  1. Conda
复制代码
conda create -n deepseek-ocr2 python=3.12.9 -y
conda activate deepseek-ocr2
  1. Packages
  • download the vllm-0.8.5 whl
复制代码
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu118
pip install vllm-0.8.5+cu118-cp38-abi3-manylinux1_x86_64.whl
pip install -r requirements.txt
pip install flash-attn==2.7.3 --no-build-isolation

Note: if you want vLLM and transformers codes to run in the same environment, you don't need to worry about this installation error like: vllm 0.8.5+cu118 requires transformers>=4.51.1

vLLM-Inference

  • VLLM:

Note: change the INPUT_PATH/OUTPUT_PATH and other settings in the DeepSeek-OCR2-master/DeepSeek-OCR2-vllm/config.py

复制代码
cd DeepSeek-OCR2-master/DeepSeek-OCR2-vllm
  1. image: streaming output
复制代码
python run_dpsk_ocr2_image.py
  1. pdf: concurrency (on-par speed with DeepSeek-OCR)
复制代码
python run_dpsk_ocr2_pdf.py
  1. batch eval for benchmarks (i.e., OmniDocBench v1.5)
复制代码
python run_dpsk_ocr2_eval_batch.py

Transformers-Inference

  • Transformers
复制代码
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)

or you can

复制代码
cd DeepSeek-OCR2-master/DeepSeek-OCR2-hf
python run_dpsk_ocr2.py

Support-Modes

  • Dynamic resolution
    • Default: (0-6)×768×768 + 1×1024×1024 --- (0-6)×144 + 256 visual tokens ✅
相关推荐
HAHAXX821 小时前
RPA 架构设计详解:大模型集成下,如何融合 NLP、OCR 处理非结构化数据
自然语言处理·ocr·rpa
聚美智数2 天前
二维码识别-条形码识别-智能识别二维码条形码-二维码OCR-二维码解析-二维码图片识别
ocr
楚识科技2 天前
CPU 环境 OCR 选型与加速实践:Tesseract / RapidOCR / PaddleOCR 轻量版 + ONNX Runtime 量化
ocr
聚美智数2 天前
VIN图片识别-车辆VIN识别-车辆VIN图片识别-车架号OCR-车架号OCR识别
ocr
聚美智数2 天前
图片去摩尔纹 - 屏幕翻拍波纹消除 - 图像摩尔纹消解 - 屏幕干涉纹修复 API 接口介绍
经验分享·ocr
楚识科技2 天前
RPA+OCR 落地实战:从截屏识别到自动入账的完整链路与选型清单
ocr·rpa
楚识科技2 天前
OCR 推理选 CPU 还是 GPU?一份可落地的算力评估与实测方案
ocr
2601_963906782 天前
离线截图 OCR 识别:支持表格与 PDF 解析
pdf·ocr·软件需求
像风一样自由20202 天前
23.OCR在知识库中的作用扫描件和图片文字如何进入RAG
postgresql·大模型·ocr·rag
学术 学术 Fun3 天前
612 次图表重建实验告诉我们的:O612 次图表重建实验告诉我们的:OCR、图形与连接线CR、图形与连接线
机器学习·计算机视觉·ocr·图表