docker部署飞桨paddleocr真的太不容易了,坑超级多  ̄へ ̄
1.构建镜像
paddleocr源码里给的CPU版的dockerfile有很多坑,我对其进行改进:
(温馨提示:镜像大概有 7G,记得腾出空间!)
# Version: 2.0.0
FROM registry.baidubce.com/paddlepaddle/paddle:2.5.0
# PaddleOCR base on Python3.7
RUN pip3.7 install --upgrade pip -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install setuptools-scm -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install lanms-neo -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install Polygon3 -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install PyWavelets -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install --upgrade ipython -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install paddlehub --upgrade -i https://mirror.baidu.com/pypi/simple
RUN git clone https://gitee.com/paddlepaddle/PaddleOCR.git /PaddleOCR
WORKDIR /PaddleOCR
RUN pip3.7 install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
RUN mkdir -p /PaddleOCR/inference/
# 模型可以到这下载:https://aistudio.baidu.com/modelsdetail?modelId=17
# Download orc detect model(light version). if you want to change normal version, you can change ch_ppocr_mobile_v2.0_det_infer to ch_ppocr_server_v2.0_det_infer, also remember change det_model_dir in deploy/hubserving/ocr_system/params.py)
ADD https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/ch_PP-OCRv3_det_infer.tar -C /PaddleOCR/inference/
# Download direction classifier(light version). If you want to change normal version, you can change ch_ppocr_mobile_v2.0_cls_infer to ch_ppocr_mobile_v2.0_cls_infer, also remember change cls_model_dir in deploy/hubserving/ocr_system/params.py)
ADD https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/ch_ppocr_mobile_v2.0_cls_infer.tar -C /PaddleOCR/inference/
# Download orc recognition model(light version). If you want to change normal version, you can change ch_ppocr_mobile_v2.0_rec_infer to ch_ppocr_server_v2.0_rec_infer, also remember change rec_model_dir in deploy/hubserving/ocr_system/params.py)
ADD https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/ch_PP-OCRv3_rec_infer.tar -C /PaddleOCR/inference/
EXPOSE 8868
CMD ["/bin/bash","-c","hub install deploy/hubserving/ocr_system/ && hub serving start -c deploy/hubserving/ocr_system/config.json"]
2.启动服务
2.1 点击启动按钮
2.2 设置端口映射
2.3 然后到containers里启动容器
2.4 启动完后会报 ImportError: cannot import name ‘RNNCell’
2023-09-12 10:20:35 Traceback (most recent call last): 2023-09-12
10:20:35 File “/usr/local/bin/hub”, line 5, in 2023-09-12
10:20:35 from paddlehub.commands.utils import execute 2023-09-12
10:20:35 File
“/usr/local/lib/python3.7/dist-packages/paddlehub/init.py”, line
54, in 2023-09-12 10:20:35 from
paddlehub.compat.task.text_generation_task import TextGenerationTask
2023-09-12 10:20:35 File
“/usr/local/lib/python3.7/dist-packages/paddlehub/compat/task/text_generation_task.py”,
line 22, in 2023-09-12 10:20:35 from paddle.fluid.layers
import RNNCell, LSTMCell, rnn, BeamSearchDecoder, dynamic_decode
2023-09-12 10:20:35 ImportError: cannot import name ‘RNNCell’ from
‘paddle.fluid.layers’
(/usr/local/lib/python3.7/dist-packages/paddle/fluid/layers/init.py)
解决方法:
2.5 进入Files
2.6 找到 user/local/lib/python3.7/dist-packages/paddlehub/compat/task/text_generation_task.py文件,进行编辑,并修改红框部分。
from paddle.nn import RNNCellBase,LSTMCell,RNN,BeamSearchDecoder,dynamic_decode
2.7 接下来找到 PaddleOCR/deploy/hubserving/ocr_system/config.json文件,修改红框部分。
2.8 修改完后保存,然后重启服务,若出现以下日志,那么恭喜你!部署成功啦(≧∇≦)ノ
好啦,这是全部的内容啦~
以下是参考资料,如果遇到其他问题也可以从下面查找:
1、PaddleOCR在windows中的使用
2、解决paddle cannot import name ‘RNNCell’ from ‘paddle.fluid.layers’ 的问题
3、Java使用PaddleOCR识别身份证信息