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 ~

相关推荐
小豆庄11 小时前
本地视频打码:多模型检测、帧间追踪与18种模糊的选型
opencv·目标检测·ai·自然语言处理·音视频·视频
gugugu.14 小时前
同一个 ReAct,两种手写方式:LangChain 文本协议 vs LangGraph 状态图
ai·langchain
小七-七牛开发者16 小时前
Tool-Use Agent 如何扩训练数据:拆解工具、任务与环境状态的 Scaling Law
ai·agent·工具调用·scalinglaw·synthapi
盼小辉丶17 小时前
PyTorch强化学习实战——从零开始实现魔方求解器
pytorch·深度学习·强化学习
hddata@18 小时前
字符切得准,文本溯得清——高维数据OCR字符分割专利获授权,赋能多行业文本安全应用
安全·ocr
wflynn18 小时前
Mistral Large 4发布,万亿参数模型的编码与安全实测数据
ai·技术
日日大王学编程18 小时前
AI 时代后端方向新人的未来规划与看法
人工智能·后端·python·ai·golang
土星云SaturnCloud19 小时前
基于边缘计算与AI视觉的智慧街面治理方案:架构设计与场景落地
服务器·人工智能·ai·边缘计算
计算机毕业编程指导师19 小时前
基于深度学习的花卉图像分类识别系统(PyTorch + ResNet50 + Django)
pytorch·python·深度学习·分类·毕业设计·迁移学习·图像分类
Elastic 中国社区官方博客20 小时前
基于 Elasticsearch 与 Jina AI 的全模态智能搜索实践:技术全解析
大数据·人工智能·elasticsearch·搜索引擎·ai·信息可视化·jina