PaddleOCR

PaddleOCR提供2种服务部署方式:

PaddleOCR 环境

https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/installation.md

python3.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
wget http://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz && cd Python-3.7.0
yum -y install gcc
yum -y install gcc-c++
yum -y install make
yum -y install zlib*
yum install libffi-devel -y
yum install openssl-devel openssl -y
./configure --prefix=/usr/local/python3
make -j8&& make install

yum groupinstall 'Development Tools' -y
yum install zlib-devel bzip2-devel openssl-devel ncurese-devel -y

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -s /usr/local/python3/bin/pip /usr/bin/pip
1
2
3
4
5
6
7
8
wget https://bootstrap.pypa.io/pip/3.5/get-pip.py
python3 get-pip.py

# 更新 #!/usr/bin/python.bak
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
yum -y upgrade
yum -y update

Paddle

useradd paddleopr
passwd paddleopr

pip的安装都用paddleopr用户。

1
2
3
4
5
6
7
8
9
10
11
pip3 install --upgrade pip

# 如果您的机器安装的是CUDA9或CUDA10,请运行以下命令安装
python3 -m pip install paddlepaddle-gpu==2.0.0 -i https://mirror.baidu.com/pypi/simple
# 如果您的机器是CPU,请运行以下命令安装
python3 -m pip install paddlepaddle==2.0.0 -i https://mirror.baidu.com/pypi/simple


git clone https://gitee.com/paddlepaddle/PaddleOCR
cd PaddleOCR
pip3 install -r requirements.txt

PaddleServing 部署

安装serving,用于启动服务

1
2
3
4
5
pip3 install paddle-serving-server==0.6.1 # for CPU
pip3 install paddle-serving-server-gpu==0.6.1 # for GPU
# 其他GPU环境需要确认环境再选择执行如下命令
pip3 install paddle-serving-server-gpu==0.6.1.post101 # GPU with CUDA10.1 + TensorRT6
pip3 install paddle-serving-server-gpu==0.6.1.post11 # GPU with CUDA11 + TensorRT7

安装client,用于向服务发送请求

在下载链接中找到对应python版本的client安装包,这里推荐python3.7版本:

1
2
wget https://paddle-serving.bj.bcebos.com/test-dev/whl/paddle_serving_client-0.0.0-cp37-none-any.whl
pip3 install paddle_serving_client-0.0.0-cp37-none-any.whl

安装serving-app

1
pip3 install paddle-serving-app==0.6.1

模型转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 下载并解压 OCR 文本检测模型
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_ppocr_mobile_v2.0_det_infer.tar
# 下载并解压 OCR 文本识别模型
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar

# 转换检测模型
python3 -m paddle_serving_client.convert --dirname ./ch_ppocr_mobile_v2.0_det_infer/ \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--serving_server ./ppocr_det_mobile_2.0_serving/ \
--serving_client ./ppocr_det_mobile_2.0_client/

# 转换识别模型
python3 -m paddle_serving_client.convert --dirname ./ch_ppocr_mobile_v2.0_rec_infer/ \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--serving_server ./ppocr_rec_mobile_2.0_serving/ \
--serving_client ./ppocr_rec_mobile_2.0_client/
异常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Error: Can not import avx core while this file exists: /home/paddleopr/.local/lib/python3.7/site-packages/paddle/fluid/core_avx.so
...
ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/paddleopr/.local/lib/python3.7/site-packages/paddle/fluid/core_avx.so)

# root,查看是否安装CXXABI_1.3.8
strings /usr/lib64/libstdc++.so.6|grep CXXABI
下载https://wwa.lanzoui.com/i8lnene
解压后放在/usr/lib64
rm -rf libstdc++.so.6
mv libstdc++.so.6.0.26 libstdc++.so.6

-------------------------
ImportError: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /lib64/libstdc++.so.6)

root执行
curl -O http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz
tar zxf glibc-2.18.tar.gz
cd glibc-2.18/
mkdir build
cd build/
../configure --prefix=/usr
make -j2
make install

启动

1
2
3
4
5
6
# 修改config.yml中模型地址
cd PaddleOCR/deploy/pdserver/
python3 web_service.py &>log.txt &

# 测试
python3 pipeline_http_client.py
异常
1
2
3
4
5
6
7
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

#查看缺少的共享库
yum whatprovides libSM.so.6
yum install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
yum install libXrender-0.9.10-1.el7.x86_64 --setopt=protected_multilib=false
yum install libXext-1.3.3-3.el7.x86_64 --setopt=protected_multilib=false