简介
PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力使用者训练出更好的模型,并应用落地。
查看本机的操作系统和位数信息
uname -m && cat /etc/*release
确认需要安装 PaddlePaddle 的 Python 是您预期的位置,因为您计算机可能有多个 Python
which python3
如果您是使用 Python 3,使用以下命令确认是 3.5.1+/3.6/3.7
python3 --version
需要确认pip的版本是否满足要求,要求pip版本为9.0.1+
如果您是使用 Python 3
python3 -m ensurepip
python3 -m pip --version
需要确认Python和pip是64bit,并且处理器架构是x86_64(或称作x64、Intel 64、AMD64)架构,目前PaddlePaddle不支持arm64架构。下面的第一行输出的是”64bit”,第二行输出的是”x86_64”、”x64”或”AMD64”即可:
使用 Python 3
python3 -c "import platform;print(platform.architecture()[0]);print(platform.machine())"
若没有安装 安装 python3 和 pip3 则使用下面命令安装
yum install python3 python3-pip -y
更新 pip3
pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
# 或者使用百度源
pip3 install --upgrade pip -i https://mirror.baidu.com/pypi/simple
安装 paddlepaddle
python3 -m pip install paddlepaddle==1.8.5 -i https://pypi.tuna.tsinghua.edu.cn/simple
安装 paddlehub
pip3 install paddlehub --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple
若安装过程没有报错,则安装成功。
若提升 timeout 超时,重新运行安装命令,或者更换源后再次运行命令
若出现版本不匹配错误,如下:
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
paddlepaddle 1.7.2 requires matplotlib<=2.2.4, but you'll have matplotlib 3.3.2 which is incompatible.
手动安装指定版本依赖,命令如下
pip3 install matplotlib==2.2.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
解决依赖错误后,重新运行响应安装命令则可安装成功
下载源码
git clone https://gitee.com/PaddlePaddle/PaddleOCR
移动到指定路径
mv PaddleOCR /PaddleOCR
安装依赖
cd /PaddleOCR
pip3 install -r requirments.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
下载模型
mkdir -p /PaddleOCR/inference && cd /PaddleOCR/inference && \
wget -c https://paddleocr.bj.bcebos.com/20-09-22/mobile/det/ch_ppocr_mobile_v1.1_det_infer.tar && \
tar xf /PaddleOCR/inference/ch_ppocr_mobile_v1.1_det_infer.tar -C /PaddleOCR/inference && \
wget -c https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_infer.tar && \
tar xf /PaddleOCR/inference/ch_ppocr_mobile_v1.1_cls_infer.tar -C /PaddleOCR/inference && \
wget -c https://paddleocr.bj.bcebos.com/20-09-22/mobile/rec/ch_ppocr_mobile_v1.1_rec_infer.tar && \
tar xf /PaddleOCR/inference/ch_ppocr_mobile_v1.1_rec_infer.tar -C /PaddleOCR/inference
安装模型
cd /PaddleOCR && export PYTHONPATH=. && \
hub install deploy/hubserving/ocr_system/
出现:Successfully installed ocr_system
则安装成功
启动服务
cd /PaddleOCR && export PYTHONPATH=. && \
hub serving start -m ocr_system
出现 Running on http://0.0.0.0:8866/
等信息,表示运行成功
若要在后台一直运行,运行如下命令
cd /PaddleOCR && export PYTHONPATH=. && \
nohup hub serving start -m ocr_system >> /PaddleOCR/hub.log 2>&1 &
测试服务
a. 计算待识别图片的Base64编码
b. 发送服务请求
curl -H "Content-Type:application/json" -X POST --data "{\"images\": [\"填入图片Base64编码(需要删除'data:image/jpg;base64,')\"]}" http://localhost:8866/predict/ocr_system
c. 返回结果(如果调用成功,会返回如下结果)
{"msg":"","results":[[{"confidence":0.8403433561325073,"text":"约定","text_region":[[345,377],[641,390],[634,540],[339,528]]},{"confidence":0.8131805658340454,"text":"最终相遇","text_region":[[356,532],[624,530],[624,596],[356,598]]}]],"status":"0"}