autodl 安装 PaddleOCR
这次我使用的试试 autodl 来部署我的 PaddleOCR ,哎公司不给我配 GPU 服务器
我用的是 RTX 2080 Ti * 1卡 的机子,所以选的是 python 3.12 、cuda 12.4 ,大概 0.93/一个小时。开机只后等待启动
我使用的是使用 JupyterLab 作为我的开发工具,进入工具之后按照这个顺序
创建一个 ipynb,添加一个代码块,执行下面的命令查下显卡支持cuda版本
!nvidia-smi
Tue Jul 8 10:59:21 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.90.07 Driver Version: 550.90.07 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 2080 Ti On | 00000000:B2:00.0 Off | N/A |
| 32% 35C P8 20W / 250W | 1MiB / 11264MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
确认是 12.4 ,之后开始安装
添加一个代码块, 根据 CUDA Version: 12.4
选择合适的安装环境,由于我这没有看到 12.4 的所以退而求其次选了 11.8 的
pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
出现了下面这个就对了
Successfully installed nvidia-cublas-cu11-11.11.3.6 nvidia-cuda-cupti-cu11-11.8.87 nvidia-cuda-nvrtc-cu11-11.8.89 nvidia-cuda-runtime-cu11-11.8.89 nvidia-cudnn-cu11-8.9.6.50 nvidia-cufft-cu11-10.9.0.58 nvidia-curand-cu11-10.3.0.86 nvidia-cusolver-cu11-11.4.1.48 nvidia-cusparse-cu11-11.7.5.86 nvidia-nccl-cu11-2.19.3 nvidia-nvtx-cu11-11.8.86 opt_einsum-3.3.0 paddlepaddle-gpu-3.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Note: you may need to restart the kernel to use updated packages.
添加一个代码块 候执行下面的命令 安装 paddleocr
pip install paddleocr
直到执行到下面的这个出来就对了
Successfully installed GPUtil-1.4.0 SQLAlchemy-2.0.41 aiohappyeyeballs-2.6.1 aiohttp-3.12.13 aiosignal-1.4.0 annotated-types-0.7.0 cachetools-6.1.0 chardet-5.2.0 colorlog-6.9.0 cssselect-1.3.0 cssutils-2.11.1 dataclasses-json-0.6.7 einops-0.8.1 et-xmlfile-2.0.0 frozenlist-1.7.0 ftfy-6.3.1 greenlet-3.2.3 hf-xet-1.1.5 httpx-sse-0.4.1 huggingface-hub-0.33.2 imagesize-1.4.1 jiter-0.10.0 joblib-1.5.1 langchain-0.3.26 langchain-community-0.3.27 langchain-core-0.3.68 langchain-openai-0.3.27 langchain-text-splitters-0.3.8 langsmith-0.4.4 lxml-6.0.0 marshmallow-3.26.1 more-itertools-10.7.0 multidict-6.6.3 mypy-extensions-1.1.0 openai-1.93.1 opencv-contrib-python-4.10.0.84 openpyxl-3.1.5 orjson-3.10.18 paddleocr-3.1.0 paddlex-3.1.1 pandas-2.3.1 premailer-3.10.0 prettytable-3.16.0 propcache-0.3.2 py-cpuinfo-9.0.0 pyclipper-1.3.0.post6 pydantic-2.11.7 pydantic-core-2.33.2 pydantic-settings-2.10.1 pypdfium2-4.30.1 python-dotenv-1.1.1 pytz-2025.2 regex-2024.11.6 requests-toolbelt-1.0.0 scikit-learn-1.7.0 scipy-1.16.0 shapely-2.1.1 tenacity-9.1.2 threadpoolctl-3.6.0 tiktoken-0.9.0 tokenizers-0.21.2 typing-inspect-0.9.0 typing-inspection-0.4.1 tzdata-2025.2 ujson-5.10.0 yarl-1.20.1 zstandard-0.23.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Note: you may need to restart the kernel to use updated packages.
安装完毕后 添加一个代码块 测试一下是否可用
from paddleocr import PaddleOCR
ocr = PaddleOCR(
use_doc_orientation_classify=False,
use_doc_unwarping=False,
use_textline_orientation=False) # 文本检测+文本识别
# ocr = PaddleOCR(use_doc_orientation_classify=True, use_doc_unwarping=True) # 文本图像预处理+文本检测+方向分类+文本识别
# ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False) # 文本检测+文本行方向分类+文本识别
# ocr = PaddleOCR(
# text_detection_model_name="PP-OCRv5_mobile_det",
# text_recognition_model_name="PP-OCRv5_mobile_rec",
# use_doc_orientation_classify=False,
# use_doc_unwarping=False,
# use_textline_orientation=False) # 更换 PP-OCRv5_mobile 模型
# 这个图片我放到了下面
result = ocr.predict("./2.png")
if __name__ == '__main__':
for res in result:
res.print()
res.save_to_img("output")
res.save_to_json("output")
结果
Creating model: ('PP-OCRv5_server_det', None)
Using official model (PP-OCRv5_server_det), the model files will be automatically downloaded and saved in /root/.paddlex/official_models.
Creating model: ('PP-OCRv5_server_rec', None)
Using official model (PP-OCRv5_server_rec), the model files will be automatically downloaded and saved in /root/.paddlex/official_models.
{'res': {'input_path': './2.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': True, 'use_textline_orientation': False}, 'doc_preprocessor_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_orientation_classify': False, 'use_doc_unwarping': False}, 'angle': -1}, 'dt_polys': array([[[144, 126],
...,
[144, 171]],
...,
[[155, 587],
...,
[155, 640]]], dtype=int16), 'text_det_params': {'limit_side_len': 64, 'limit_type': 'min', 'thresh': 0.3, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 1.5}, 'text_type': 'general', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['风速', '中速', 'FAN', 'MED', '23', '30', 'C', '室内', 'C', '设定', '温度', '温度', 'SET TEMP', 'ROOM TEMP', '模式', '冷风', 'MODE', 'COOL', 'QuanLing'], 'rec_scores': array([0.99813688, ..., 0.9915992 ]), 'rec_polys': array([[[144, 126],
...,
[144, 171]],
...,
[[155, 587],
...,
[155, 640]]], dtype=int16), 'rec_boxes': array([[144, ..., 171],
...,
[155, ..., 640]], dtype=int16)}}
Connecting to https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/fonts/simfang.ttf ...
Downloading simfang.ttf ...
[==================================================] 100.00%
Connecting to https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/fonts/PingFang-SC-Regular.ttf ...
Downloading PingFang-SC-Regular.ttf ...
[==================================================] 100.00%
可以看到文件列表里面有 output 目录
打开目录找到 2_ocr_res_img.png 打开看看是不是成了
启动服务模式
这时候关了刚才的笔记本,重新创建一个终端
执行下面的命令,安装 serving
paddlex --install serving
Installing collected packages: filetype, pycryptodome, future, click, uvicorn, starlette, bce-python-sdk, fastapi
Successfully installed bce-python-sdk-0.9.35 click-8.2.1 fastapi-0.116.0 filetype-1.2.0 future-1.0.0 pycryptodome-3.23.0 starlette-0.46.2 uvicorn-0.35.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
测试一下 通用产线服务
paddlex --serve --pipeline OCR
如果都成功这时候会看到下面的内容
[==================================================] 100.00%
Creating model: ('PP-OCRv5_server_det', None)
Using official model (PP-OCRv5_server_det), the model files will be automatically downloaded and saved in /root/.paddlex/official_models.
Creating model: ('PP-OCRv5_server_rec', None)
Using official model (PP-OCRv5_server_rec), the model files will be automatically downloaded and saved in /root/.paddlex/official_models.
INFO: Started server process [16847]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
此时还不能直接用我们需要通过 autodl 的客户端来访问
下载后解压打开 AutoDL.exe ,填入 SSH登录 的 登录指令 和 密码 。红色箭头的这里有改成你要代理的端口
点击开始代理即可
这个红色的箭头就是要用的地址,起一个 curl 或者 apipost 测试下
curl --request POST \
--url http://127.0.0.1:8080/ocr \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 106' \
--header 'Content-Type: application/json' \
--header 'Host: 127.0.0.1:8080' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0' \
--data '{
"file": "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png"
}'
{
"logId": "d581d243-8bc6-48af-9d3a-e814fad05b88",
"result": Object{...},
"errorCode": 0,
"errorMsg": "Success"
}
查看里面是否有需要的内容。
其他
使用脚本启动服务
start.sh
#!/bin/bash
# 定义日志文件名
LOG_FILE="app_runtime.log"
# 查找并杀掉已经存在的进程
PID=$(ps -ef | grep "paddlex --serve --pipeline OCR" | grep -v grep | awk '{print $2}')
if [ ! -z "$PID" ]; then
echo "Found existing process with PID: $PID. Killing it now."
kill -9 $PID
fi
# 使用 nohup 启动 Python 脚本
# > $LOG_FILE: 将标准输出重定向到日志文件
# 2>&1: 将标准错误重定向到标准输出 (即也写入日志文件)
# &: 在后台运行
echo "Starting paddlex --serve --pipeline OCR"
nohup paddlex --serve --pipeline OCR > $LOG_FILE 2>&1 &
# 将进程ID (PID) 保存到文件中,方便之后关闭
echo $! > run.pid
echo "Application started successfully. PID: $(cat run.pid). Log is being written to $LOG_FILE."
stop.sh
#!/bin/bash
if [ -f "run.pid" ]; then
PID=$(cat run.pid)
echo "Found PID file. Stopping process with PID: $PID..."
kill $PID
# 检查进程是否真的被关闭
sleep 2
if ps -p $PID > /dev/null; then
echo "Process $PID did not stop. Forcing kill..."
kill -9 $PID
fi
rm run.pid
echo "Process stopped."
else
echo "PID file (run.pid) not found. Trying to find and kill the process by name..."
# 如果 PID 文件丢失,尝试通过进程名查找并杀死
pkill -f " paddlex --serve --pipeline OCR"
if [ $? -eq 0 ]; then
echo "Process killed by name."
else
echo "No running process found."
fi
fi
服务化部署相关的命令行选项如下
--pipeline PaddleX 产线注册名或产线配置文件路径。
--device 产线部署设备。默认情况下,当 GPU 可用时,将使用 GPU;否则使用 CPU。
--host 服务器绑定的主机名或 IP 地址。默认为 0.0.0.0。
--port 服务器监听的端口号。默认为 8080。
--use_hpip 如果指定,则使用高性能推理。请参考高性能推理文档了解更多信息。
--hpi_config 高性能推理配置。请参考高性能推理文档了解更多信息。
PaddleOCR 产线 和 PaddleX 产线对应关系,也就是 --pipeline
参数的值
例如:paddlex --serve --pipeline PP-StructureV3
PaddleOCR 产线 | PaddleX 产线注册名 |
---|---|
通用 OCR | OCR |
PP-StructureV3 | PP-StructureV3 |
PP-ChatOCRv4 | PP-ChatOCRv4-doc |
通用表格识别 v2 | table_recognition_v2 |
公式识别 | formula_recognition |
印章文本识别 | seal_recognition |
文档图像预处理 | doc_preprocessor |
文档理解 | doc_understanding |
PP-DocTranslation | PP-DocTranslation |