diff --git a/deploy/pdserving/det_local_server.py b/deploy/pdserving/det_local_server.py index acfccdb6..78970af4 100644 --- a/deploy/pdserving/det_local_server.py +++ b/deploy/pdserving/det_local_server.py @@ -21,7 +21,10 @@ from paddle_serving_client import Client from paddle_serving_app.reader import Sequential, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose from paddle_serving_app.reader import DBPostProcess, FilterBoxes -from paddle_serving_server_gpu.web_service import WebService +if sys.argv[1] == 'gpu': + from paddle_serving_server_gpu.web_service import WebService +elif sys.argv[1] == 'cpu' + from paddle_serving_server.web_service import WebService import time import re import base64 @@ -64,8 +67,11 @@ class OCRService(WebService): ocr_service = OCRService(name="ocr") ocr_service.load_model_config("ocr_det_model") -ocr_service.set_gpus("0") -ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +if sys.argv[1] == 'gpu': + ocr_service.set_gpus("0") + ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +elif sys.argv[1] == 'cpu': + ocr_service.prepare_server(workdir="workdir", port=9292) ocr_service.init_det() ocr_service.run_debugger_service() ocr_service.run_web_service() diff --git a/deploy/pdserving/det_web_server.py b/deploy/pdserving/det_web_server.py index dd69be0c..14be7413 100644 --- a/deploy/pdserving/det_web_server.py +++ b/deploy/pdserving/det_web_server.py @@ -21,7 +21,10 @@ from paddle_serving_client import Client from paddle_serving_app.reader import Sequential, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose from paddle_serving_app.reader import DBPostProcess, FilterBoxes -from paddle_serving_server_gpu.web_service import WebService +if sys.argv[1] == 'gpu': + from paddle_serving_server_gpu.web_service import WebService +elif sys.argv[1] == 'cpu': + from paddle_serving_server.web_service import WebService import time import re import base64 @@ -65,8 +68,11 @@ class OCRService(WebService): ocr_service = OCRService(name="ocr") ocr_service.load_model_config("ocr_det_model") -ocr_service.set_gpus("0") -ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +if sys.argv[1] == 'gpu': + ocr_service.set_gpus("0") + ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +elif sys.argv[1] == 'cpu': + ocr_service.prepare_server(workdir="workdir", port=9292, device="cpu") ocr_service.init_det() ocr_service.run_rpc_service() ocr_service.run_web_service() diff --git a/deploy/pdserving/ocr_local_server.py b/deploy/pdserving/ocr_local_server.py index 93e2d7a3..f7458c30 100644 --- a/deploy/pdserving/ocr_local_server.py +++ b/deploy/pdserving/ocr_local_server.py @@ -22,7 +22,10 @@ from paddle_serving_client import Client from paddle_serving_app.reader import Sequential, URL2Image, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose from paddle_serving_app.reader import DBPostProcess, FilterBoxes, GetRotateCropImage, SortedBoxes -from paddle_serving_server_gpu.web_service import WebService +if sys.argv[1] == 'gpu': + from paddle_serving_server_gpu.web_service import WebService +elif sys.argv[1] == 'cpu': + from paddle_serving_server.web_service import WebService from paddle_serving_app.local_predict import Debugger import time import re @@ -37,8 +40,12 @@ class OCRService(WebService): (2, 0, 1)) ]) self.det_client = Debugger() - self.det_client.load_model_config( - det_model_config, gpu=True, profile=False) + if sys.argv[1] == 'gpu': + self.det_client.load_model_config( + det_model_config, gpu=True, profile=False) + elif sys.argv[1] == 'cpu': + self.det_client.load_model_config( + det_model_config, gpu=False, profile=False) self.ocr_reader = OCRReader() def preprocess(self, feed=[], fetch=[]): @@ -99,5 +106,8 @@ ocr_service = OCRService(name="ocr") ocr_service.load_model_config("ocr_rec_model") ocr_service.prepare_server(workdir="workdir", port=9292) ocr_service.init_det_debugger(det_model_config="ocr_det_model") -ocr_service.run_debugger_service(gpu=True) +if sys.argv[1] == 'gpu': + ocr_service.run_debugger_service(gpu=True) +elif sys.argv[1] == 'cpu': + ocr_service.run_debugger_service() ocr_service.run_web_service() diff --git a/deploy/pdserving/ocr_web_server.py b/deploy/pdserving/ocr_web_server.py index d017f6b9..6c0de446 100644 --- a/deploy/pdserving/ocr_web_server.py +++ b/deploy/pdserving/ocr_web_server.py @@ -22,7 +22,10 @@ from paddle_serving_client import Client from paddle_serving_app.reader import Sequential, URL2Image, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose from paddle_serving_app.reader import DBPostProcess, FilterBoxes, GetRotateCropImage, SortedBoxes -from paddle_serving_server_gpu.web_service import WebService +if sys.argv[1] == 'gpu': + from paddle_serving_server_gpu.web_service import WebService +elif sys.argv[1] == 'cpu': + from paddle_serving_server.web_service import WebService import time import re import base64 @@ -90,8 +93,11 @@ class OCRService(WebService): ocr_service = OCRService(name="ocr") ocr_service.load_model_config("ocr_rec_model") -ocr_service.set_gpus("0") -ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +if sys.argv[1] == 'gpu': + ocr_service.set_gpus("0") + ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=0) +elif sys.argv[1] == 'cpu': + ocr_service.prepare_server(workdir="workdir", port=9292) ocr_service.init_det_client( det_port=9293, det_client_config="ocr_det_client/serving_client_conf.prototxt") diff --git a/deploy/pdserving/readme.md b/deploy/pdserving/readme.md index d6069cd3..60becf13 100644 --- a/deploy/pdserving/readme.md +++ b/deploy/pdserving/readme.md @@ -16,20 +16,33 @@ **Python3操作指南:** ``` -#以下提供beta版本的paddle serving whl包,欢迎试用,正式版会在7月底正式上线 +#以下提供beta版本的paddle serving whl包,欢迎试用,正式版会在8月中正式上线 +#GPU用户下载server包使用这个链接 wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_server_gpu-0.3.2-py3-none-any.whl +python -m pip install paddle_serving_server_gpu-0.3.2-py3-none-any.whl +#CPU版本请下载以下whl包使用这个链接 +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_server-0.3.2-py3-none-any.whl +python -m pip install paddle_serving_server-0.3.2-py3-none-any.whl +#客户端和App包使用以下链接(CPU,GPU通用) wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_client-0.3.2-cp36-none-any.whl wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_app-0.1.2-py3-none-any.whl -python -m pip install paddle_serving_app-0.1.2-py3-none-any.whl paddle_serving_server_gpu-0.3.2-py3-none-any.whl paddle_serving_client-0.3.2-cp36-none-any.whl +python -m pip install paddle_serving_app-0.1.2-py3-none-any.whl paddle_serving_client-0.3.2-cp36-none-any.whl ``` **Python2操作指南:** ``` -#以下提供beta版本的paddle serving whl包,欢迎试用,正式版会在7月底正式上线 +#以下提供beta版本的paddle serving whl包,欢迎试用,正式版会在8月中正式上线 +#GPU用户下载server包使用这个链接 wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_server_gpu-0.3.2-py2-none-any.whl +python -m pip install paddle_serving_server_gpu-0.3.2-py2-none-any.whl +#CPU版本请下载以下whl包使用这个链接 +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_server-0.3.2-py2-none-any.whl +python -m pip install paddle_serving_server-0.3.2-py2-none-any.whl + +#客户端和App包使用以下链接(CPU,GPU通用) wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_app-0.1.2-py2-none-any.whl wget --no-check-certificate https://paddle-serving.bj.bcebos.com/others/paddle_serving_client-0.3.2-cp27-none-any.whl -python -m pip install paddle_serving_app-0.1.2-py2-none-any.whl paddle_serving_server_gpu-0.3.2-py2-none-any.whl paddle_serving_client-0.3.2-cp27-none-any.whl +python -m pip install paddle_serving_app-0.1.2-py2-none-any.whl paddle_serving_client-0.3.2-cp27-none-any.whl ``` ### 2. 模型转换 @@ -54,13 +67,19 @@ tar -xzvf ocr_det.tar.gz ``` python -m paddle_serving_server_gpu.serve --model ocr_det_model --port 9293 --gpu_id 0 -python ocr_web_server.py +# cpu,gpu启动二选一,以下是cpu启动 +python ocr_web_server.py cpu +# gpu启动 +python ocr_web_server.py gpu ``` #### 方式2. 启动快速版服务 ``` -python ocr_local_server.py +# cpu,gpu启动二选一,以下是cpu启动 +python ocr_local_server.py cpu +# gpu启动 +python ocr_local_server.py gpu ``` ## 发送预测请求 @@ -85,7 +104,7 @@ python ocr_web_client.py 在`ocr_web_server.py`或是`ocr_local_server.py`当中的`preprocess`函数里面做了检测服务和识别服务的前处理,`postprocess`函数里面做了识别的后处理服务,可以在相应的函数中做修改。调用了`paddle_serving_app`库提供的常见CV模型的前处理/后处理库。 -如果想要单独启动Paddle Serving的检测服务和识别服务,参见下列表格, 执行对应的脚本即可。 +如果想要单独启动Paddle Serving的检测服务和识别服务,参见下列表格, 执行对应的脚本即可,并且在命令行参数注明用的CPU或是GPU来提供服务。 | 模型 | 标准版 | 快速版 | | ---- | ----------------- | ------------------- |