diff --git a/deploy/pdserving/det_local_server.py b/deploy/pdserving/det_local_server.py index acfccdb6d24a7e1ba490705dd147f21dbf921d31..78970af4d1a8a89f976f48f2c29ec97732afa0ce 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 dd69be0c70eb0f4dd627aa47ad33045a204f78c0..14be74130dcb413c31a3e76c150d74f65575f451 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 93e2d7a3d1dc64451774ecf790c2ebd3b39f1d91..f7458c3036734e4bb6e554097029270e11912a3a 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 d017f6b9b560dc82158641b9f3a9f80137b40716..6c0de44661958a6425f57039261969551ff552c5 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 d6069cd35d201ee7418324c5d9b0b8b28c6569bd..60becf137405183522e0b15c35958c32fd351b5a 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来提供服务。 | 模型 | 标准版 | 快速版 | | ---- | ----------------- | ------------------- |