使用docker部署建议还是先了解docker,部署PaddleOCR我是有docker基础但无python基础。
详细安装步骤可以参考这篇文章:
PaddleOCR——Docker环境下基于HubServing模式部署Restful API服务(CPU版本)_无限迭代中......-CSDN博客
这篇文章写得很清晰,基本看几遍就懂了。但是按照上面操作一遍会发现还是不行的,看评论区也有人发现不行。
主要原因是dockerfile
# Version: 2.0.0
FROM registry.baidubce.com/paddlepaddle/paddle:2.1.2
# PaddleOCR base on Python3.7
RUN pip3.7 install --upgrade pip -i https://mirror.baidu.com/pypi/simple
RUN pip3.7 install paddlehub --upgrade -i https://mirror.baidu.com/pypi/simple
RUN git clone https://github.com/PaddlePaddle/PaddleOCR.git /PaddleOCR
ADD https://raw.githubusercontent.com/python/cpython/3.7/Lib/typing.py /usr/local/lib/python3.7
WORKDIR /PaddleOCR
RUN pip3.7 install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
RUN mkdir -p /PaddleOCR/inference/
# 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 {link} /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/{file} -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 {link} /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/{file}.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 {link} /PaddleOCR/inference/
RUN tar xf /PaddleOCR/inference/{file}.tar -C /PaddleOCR/inference/
EXPOSE 8868
CMD ["/bin/bash","-c","hub install deploy/hubserving/ocr_system/ && hub serving start -m ocr_system"]
先说遇到第一个困难点就是
ADD https://raw.githubusercontent.com/python/cpython/3.7/Lib/typing.py /usr/local/lib/python3.7
死活连不上https://raw.githubusercontent.com/python/cpython/3.7/Lib/typing.py地址,后来我是参考以下这篇文章的:
https://segmentfault.com/a/1190000021637275https://segmentfault.com/a/1190000021637275我的建议是手动下载下来,因为我也是build很多次镜像才成功,连接失败率很大。
其次最困惑的点:
ADD {link} /PaddleOCR/inference/
就是{link}和{file}标签问题,我一直以为这是环境变量,还是什么变量,直到我看了第二篇文章。上面的英文注释我水平有限不是很能理解。在我多次查其他资料的时候,发现这些其实是需要的模型
我圈出来的地方就是告诉你需要用到的文件 ,这就是其他大佬博客贴出来dockerfile跟官方不一样,官方的不能直接使用。
请原谅我水平低,反正我是在这里困惑了很久。
还有最后一个比较谜的地方
EXPOSE 8868
8868这个端口,我build和跑都能成功,但docker logs -f paddle_ocr
发现其中显示的端口居然是8866,这就是为什么有些博客也是写8866,但我看了ocr_system的json配置文件,确实是8868.
我最后也是修改了8866之后才能使用起来,至今都不知道什么原因,希望有大神告知一下,哪里可以设置。这个官方的dockerfile实在迷人。我前前后后build数次才能正常运行,希望大家不要轻易放弃。