PaddleOCR 开始

PaddleOCR-VL-1.6 (0.9B) 是 SOTA 级文档视觉语言模型 (VLM)。

该模型以 96.3% 精度刷新 OmniDocBench v1.6,文本、公式、表格识别全面领先,并在古籍、生僻字、印章、图表等多场景能力显著增强,支持以 Markdown 和 JSON 格式输出结构化结果。

官方支持一键部署多种硬件后端(NVIDIA GPU、昆仑芯 XPU、昇腾 NPU等)、无缝集成 Dify、RAGFlow、Pathway和Cherry Studio。

本文将介绍两种方式来部署 PaddleOCR-VL-1.6 的推理服务,

  • 官方 Docker 方式: 官方强烈推荐采用该方式,以最大程度减少可能出现的环境问题
    • 官方其他方式,可以纯 Paddle。但如果想 vLLM 等推理,要独立环境,不混一起
  • 社区 ONNX 方式: 社区 Python 生态推理,脱离对官方 Paddle 工程的依赖

Docker 方式

若无 Docker 环境,请见下一节做准备;已有,则直接做部署。
NVIDIA GPU 推理时,需要注意 Compute Capability(简称 CC)和 CUDA 版本是否满足要求。

总体上建议 CC ≥ 8.0,CUDA ≥ 12.6,RTX 30 系列及以上,详见这里。

版本要求: Docker >= 19.03, CUDA >= 12.6

启动服务(offline),

bash 复制代码
docker run \
-it \
--rm \
--gpus all \
--network host \
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddleocr-genai-vllm-server:latest-nvidia-gpu-offline \
paddleocr genai_server --model_name PaddleOCR-VL-1.6-0.9B --host 0.0.0.0 --port 8118 --backend vllm

启动信息,

bash 复制代码
(APIServer pid=1) INFO 08-10 08:08:08 [api_server.py:1971] Starting vLLM API server 0 on http://0.0.0.0:8118
...
(APIServer pid=1) INFO:     Started server process [1]
(APIServer pid=1) INFO:     Waiting for application startup.
(APIServer pid=1) INFO:     Application startup complete.
(APIServer pid=1) INFO:     127.0.0.1:45962 - "GET /health HTTP/1.1" 200 OK
(APIServer pid=1) [2026/08/10 08:08:08] paddleocr INFO: The PaddleOCR GenAI server has been started. You can either:
(APIServer pid=1)     1. Set the server URL in the module or pipeline configuration and call the PaddleOCR CLI or Python API. For example:
(APIServer pid=1)         paddleocr doc_parser --input demo.png --vl_rec_backend vllm-server --vl_rec_server_url http://localhost:8118/v1
(APIServer pid=1)     2. Make HTTP requests directly, or using the OpenAI client library.

显存占用大约 10G。

更多:

Docker 环境

安装 Docker,

bash 复制代码
$ docker -v
Docker version 29.6.2, build dfc4efb
$ docker compose version
Docker Compose version v5.3.1
bash 复制代码
# docker group
#  https://docs.docker.com/engine/install/linux-postinstall/
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

安装 NVIDIA Container Toolkit,

bash 复制代码
sudo systemctl restart docker
docker run --rm --runtime=nvidia --gpus all ubuntu:24.04 nvidia-smi

ONNX 方式

若无 Conda 环境,请见下一节做准备;已有,则直接做部署。

创建环境(py=3.12),

bash 复制代码
conda create -n ppocr python=3.12 -y
conda activate ppocr

准备 PaddleOCR-VL 独立工程(不依赖官方工程),

bash 复制代码
git clone --depth 1 https://github.com/devymex/paddleocr-vl-green.git
cd paddleocr-vl-green

# 可注释 onnxruntime,打开 onnxruntime-gpu,用上 GPU
# vi requirements.txt

pip install -r requirements.txt

准备模型进 ppocr/,

  • 版面检测模型 pp_doclayoutv3.onnx

  • 朝向检测模型 pp_lcnet_doc_ori.onnx

  • VL 识别模型 PaddleOCR-VL-1.6

    bash 复制代码
    # 方式一:使用 huggingface-cli
    unset http_proxy; unset https_proxy; unset all_proxy
    hf download PaddlePaddle/PaddleOCR-VL-1.6 \
        --local-dir ppocr/paddleocr-vl-1.6
    
    # 方式二:使用 git lfs
    git clone https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.6 \
        ppocr/paddleocr-vl-1.6

启动服务,

bash 复制代码
# 单 GPU(1 个 worker,使用 GPU 0),启用朝向检测
CUDA_VISIBLE_DEVICES=0 python -m scripts.server \
--model-path ppocr/paddleocr-vl-1.6 \
--layout-onnx ppocr/pp_doclayoutv3.onnx \
--orientation-onnx ppocr/pp_docorix1.onnx \
--device cuda:0 --port 8004

显存占用大约 6G。

测试服务,

bash 复制代码
# 同时启用朝向检测和版面检测
$ python - <<-EOF
import base64
import requests
import json

with open("sample/contract.jpg", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode('utf-8')

data = {
    "image": f"data:image/jpeg;base64,{img_b64}",
    "format": "json",
    "layout": True,
    "orientation": True
}

url = "http://localhost:8004/process"
response = requests.post(url, json=data)

print(f"Status Code: {response.status_code}")
print("Response:")
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
EOF

# 响应
Status Code: 200
Response:
{
  "blocks": [
    {
      "content": "波纹补偿器购售合同",
      "label": "doc_title"
    },
    {
      "content": "项目名称:中铁(北京)商务广场",
      "label": "text"
    },
...

Conda 环境

安装 Miniconda,

bash 复制代码
# 安装 Miniconda 对应版本,如 Linux x86_64,都 yes
#  https://www.anaconda.com/docs/getting-started/miniconda/install
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

# 配置镜像源(清华)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

结语

Let's Go Coding ~

相关推荐
强哥聊算力27 分钟前
《算力江湖·英伟达传奇》第七集:ChatGPT出现前夜,英伟达发生了什么?
服务器·人工智能·算法·ai·chatgpt·gpu算力
空空dream5 小时前
03 | 离线部署 FastAPI + Ollama(qwen2:0.5b):从 Docker 联调到 Kubernetes 验收
docker·ai·kubernetes·fastapi
秋饼5 小时前
Spring AI 2.0 结构化输出企业级实战:从 BeanOutputConverter 源码到生产级解析容错
java·ai·技术分享·后端开发
Smoothcloud润云6 小时前
PyTorch推理服务模型热切换与失败回滚实战:降低版本更新中断
服务器·人工智能·pytorch·python·深度学习·gpu
goehou6 小时前
Prompt 注入实战:直接注入、间接注入和四道防线(附测试样例)
安全·ai·llm·agent·prompt注入
朝朝辞暮i7 小时前
第 22 课:Conditional 1D U-Net——Diffusion Policy 怎样理解一整段未来动作?
人工智能·pytorch·深度学习·transformer·vla
小七-七牛开发者8 小时前
Personal Agent 真能越用越懂你吗?AdaptArena 揭示个性化 Web Agent 的失效链路
ai·agent·web agent·personal agent·adaptarena·个性化智能体
XLYcmy8 小时前
AI 赋能后中文与英文数据库对比分析报告 上
数据库·ai·llm·prompt·检索·wos·cnki
独码侠9 小时前
第04篇·Codex Harness 审批×权限边界:4 档策略怎么选,密钥与仓库永远碰不到
ai·agent·codex
liferecords10 小时前
PolyOCR-Venus:蚂蚁把 OCR 从『抄写员』练成『视觉智能体』,教师蒸馏还会自己下岗
大模型·ocr·强化学习·多模态