目录

基于CPU使用paddlex-OCR识别图片内容

基于CPU使用paddlex OCR识别图片内容

paddlex CPU版本使用avx指令加速,需要确保系统和CPU支持avx指令(centos 7不支持)。

检查是否支持avx指令

dmesg | grep -i avx

查看 x86还是arm

uname -m
 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
Miniconda3 will now be installed into this location:
/home/super/miniconda3

[/home/super/miniconda3] >>> 
PREFIX=/home/super/miniconda3
 source ~/.bashrc  # 若使用 Bash
conda --version
conda create -n PaddleImageOcr python=3.10.15
conda activate PaddleImageOcr
python --version
 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
    conda config --set show_channel_urls yes
conda config --show channels

临时切换国内源

export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple

CPU 版本

  python -m pip install paddlepaddle==3.0.0rc0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/

GPU 版本,需显卡驱动程序版本 ≥450.80.02(Linux)或 ≥452.39(Windows)

  python -m pip install paddlepaddle-gpu==3.0.0rc0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/

GPU 版本,需显卡驱动程序版本 ≥545.23.06(Linux)或 ≥545.84(Windows)

  python -m pip install paddlepaddle-gpu==3.0.0rc0 -i https://www.paddlepaddle.org.cn/packages/stable/cu123/
  pip install https://paddle-model-ecology.bj.bcebos.com/paddlex/whl/paddlex-3.0.0rc0-py3-none-any.whl
  paddlex --pipeline OCR --input ./20250306-152918.jpg --device cpu
  paddlex --pipeline OCR --input D:/temp/tess4j/20250306-152918.jpg --device cpu

https://i-blog.csdnimg.cn/direct/4433e80bb9f0487bae7ce3b9054fe16d.png

耗时10s,准确率较高,图片分辨率不高也能识别。

https://i-blog.csdnimg.cn/direct/000efe3fb0a340c5837b5c210ffc4755.png

安装服务化部署插件

  paddlex --install serving

启动服务

nohup paddlex --serve --port 8080 --pipeline OCR --device cpu --save_path /tmp/PaddleImageOcr > paddleImageOcr.log 2>&1 &

http请求

curl --location '127.0.0.1:8080/ocr' \
--header 'Content-Type: application/json' \
--data '{
   "file":"https://oss.xxx.com/image/xxx.jpg"
}'

设定安装源、信任安装源、PIL已被Pillow替代

 pip install Pillow -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn