Docker环境下基于HubServing模式部署Restful API服务(CPU版本)
在日常项目应用中,相信大家一般都会希望能通过Docker技术,把PaddleOCR服务打包成一个镜像,以便在Docker或k8s环境里,快速发布上线使用。
1.实施前提准备
需要先完成如下基本组件的安装:
Docker环境
Git环境
2.制作镜像
a.下载PaddleOCR项目代码
git clone https://github.com/PaddlePaddle/PaddleOCR.git
国内使用码云更快
git clone https://gitee.com/paddlepaddle/PaddleOCR.git
b.切换至CPU版本的Dockerfile目录(注:需要区分cpu或gpu版本,本文以cpu为例,gpu版本需要替换一下关键字即可)
cd PaddleOCR/deploy/docker/hubserving/cpu
c.生成镜像
docker build -t paddleocr:cpu .
下载量比较大
修改下载源:PaddleOCR Docker化部署服务
d. 查看镜像
docker image ls
3.启动Docker容器
a. 启动
sudo docker run -dp 8866:8866 --name paddle_ocr paddleocr:cpu
b. 查看容器运行情况
docker ps -a
c. 检查服务运行情况(出现:Successfully installed ocr_system和Running on http://0.0.0.0:8866/等信息,表示运行成功)
docker logs -f paddle_ocr
4.测试服务
a. 计算待识别图片的Base64编码(如果只是测试一下效果,可以通过免费的在线工具实现,如:http://tool.chinaz.com/tools/imgtobase/)
注意图片不能过大,不然curl会出错。
b. 发送服务请求(可参见sample_request.txt中的值)
sample_request.txt 中内容并不可以用于测试。
curl -H "Content-Type:application/json" -X POST --data "{\"images\": [\"iVBORw0KGgoAAAANSUhEUgAAAgsAAAA6CAYAAAA+5hrvAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAqgSURBVHhe7Zvdkdy4DkZvaPfx5uAQ/OIQHIKrJgFn4PKrc7DfNoWprU2ir/gDEgRBSt1S21LvOVUsj1r8AYEPGNgz/s8NAAAAYALNAgAAAEyhWQAAAIApNAsAAAAwhWYBAAAAptAsAAAAwBSaBQAAAJhCswAAAABTaBYAAABgimkW/rp9+d/X26/8tI2w5vPt29/h639u3z6tr3///vn237e/0p93n7eNuPenH7f3/Pzr7cM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FJoFAAAAmEKzAAAAAFNoFgAAAGAKzQIAAABMoVkAAACAKTQLAAAAMIVmAQAAAKbQLAAAAMAUmgUAAACYQrMAAAAAU2gWAAAAYArNAgAAAEyhWQAAAIApNAsAAAAwhWYBAAAAptAsAAAAwITb7f89O39CErAWkQAAAABJRU5ErkJggg==\"]}" 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"}