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 ~

相关推荐
叶小鸡2 小时前
Trae + Apifox MCP:让 AI 自动协同前后端接口文档
ai·编辑器
JaydenAI2 小时前
[基于OpenEvals的自动化评估-16]自动模拟多轮对话实施评估
ai·langchain·agent·evaluation·openevals
fthux3 小时前
装闭 RenoPit 源码解析(08):多模态AI调用、重试与文本降级
人工智能·ai·开源·github·open source·renopit
tachibana23 小时前
文件上传分布式限流如何做?
人工智能·ai·大模型·llm·prompt
智码看视界3 小时前
Day49-AI微服务化-将大模型能力封装为标准微服务
java·微服务·ai·架构·大模型·sse流式输出·ai中台
安逸sgr4 小时前
激活函数有什么用?Sigmoid、Tanh、ReLU 到底怎么选?
人工智能·ai·大模型·agent·智能体
熊猫钓鱼>_>4 小时前
Seedance 2.0 技术深度解析:重构AI视频生成的世界模型新范式
人工智能·笔记·ai·重构·音视频·变革·sedence2.0
VIP_CQCRE4 小时前
用 Ace Data Cloud Studio,把内容营销变成自动运行的 AI 工作流
ai·自动化·内容营销·mcp·acedatacloud
阿克兔4 小时前
建筑兔零基础AI自学记录120|实战1
ai