From 5b62600369d43521764ea711dac8ae25ee5b48c1 Mon Sep 17 00:00:00 2001 From: wangjiawei04 Date: Tue, 11 Aug 2020 15:22:03 +0800 Subject: [PATCH] add readme and refine ocr det/rec service --- python/examples/ocr/README.md | 25 ++++++++++++----- python/examples/ocr/README_CN.md | 31 +++++++++++++--------- python/examples/ocr/det_debugger_server.py | 12 ++++++--- python/examples/ocr/det_web_server.py | 12 ++++++--- python/examples/ocr/ocr_debugger_server.py | 18 ++++++++++--- python/examples/ocr/ocr_web_server.py | 12 ++++++--- python/examples/ocr/rec_web_server.py | 12 ++++++--- 7 files changed, 88 insertions(+), 34 deletions(-) diff --git a/python/examples/ocr/README.md b/python/examples/ocr/README.md index ca9bbabd..43dcb30e 100644 --- a/python/examples/ocr/README.md +++ b/python/examples/ocr/README.md @@ -21,8 +21,13 @@ tar xf test_imgs.tar ### Start Service ``` +#choose one of cpu/gpu commands as following +#for cpu user +python -m paddle_serving_server.serve --model ocr_det_model --port 9293 +python ocr_web_server.py cpu +#for gpu user python -m paddle_serving_server_gpu.serve --model ocr_det_model --port 9293 --gpu_id 0 -python ocr_web_server.py +python ocr_web_server.py gpu ``` ### Client Prediction @@ -33,7 +38,11 @@ If you want a faster web service, please try Web Debugger Service ## Web Debugger Service ``` -python ocr_debugger_server.py +#choose one of cpu/gpu commands as following +#for cpu user +python ocr_debugger_server.py cpu +#for gpu user +python ocr_debugger_server.py gpu ``` ## Web Debugger Client Prediction @@ -60,9 +69,11 @@ if you are going to detect images not recognize it or directly recognize the wor ### Det Server ``` -python det_web_server.py +python det_web_server.py cpu #for cpu user +python det_web_server.py gpu #for gpu user #or -python det_debugger_server.py +python det_debugger_server.py cpu #for cpu user +python det_debugger_server.py gpu #for gpu user ``` ### Det Client @@ -75,9 +86,11 @@ python ocr_web_client.py ### Rec Server ``` -python rec_web_server.py +python rec_web_server.py cpu #for cpu user +python rec_web_server.py gpu #for gpu user #or -python rec_debugger_server.py +python rec_debugger_server.py cpu #for cpu user +python rec_debugger_server.py gpu #for gpu user ``` ### Rec Client diff --git a/python/examples/ocr/README_CN.md b/python/examples/ocr/README_CN.md index 65bc066a..8bdc45cf 100644 --- a/python/examples/ocr/README_CN.md +++ b/python/examples/ocr/README_CN.md @@ -15,19 +15,18 @@ wget --no-check-certificate https://paddle-serving.bj.bcebos.com/ocr/test_imgs.t tar xf test_imgs.tar ``` -### 客户端预测 - -``` -python ocr_rpc_client.py -``` - ## Web Service服务 ### 启动服务 ``` +#根据CPU/GPU设备选择一种启动方式 +#for cpu user +python -m paddle_serving_server.serve --model ocr_det_model --port 9293 +python ocr_web_server.py cpu +#for gpu user python -m paddle_serving_server_gpu.serve --model ocr_det_model --port 9293 --gpu_id 0 -python ocr_web_server.py +python ocr_web_server.py gpu ``` ### 启动客户端 @@ -38,7 +37,11 @@ python ocr_web_client.py 如果用户需要更快的执行速度,请尝试Debugger版Web服务 ## 启动Debugger版Web服务 ``` -python ocr_debugger_server.py +#根据CPU/GPU设备选择一种启动方式 +#for cpu user +python ocr_debugger_server.py cpu +#for gpu user +python ocr_debugger_server.py gpu ``` ## 启动客户端 @@ -66,9 +69,11 @@ GPU: Nvidia Tesla V100单卡 ### 启动检测服务 ``` -python det_web_server.py +python det_web_server.py cpu #for cpu user +python det_web_server.py gpu #for gpu user #or -python det_debugger_server.py +python det_debugger_server.py cpu #for cpu user +python det_debugger_server.py gpu #for gpu user ``` ### 检测服务客户端 @@ -81,9 +86,11 @@ python ocr_web_client.py ### 启动识别服务 ``` -python rec_web_server.py +python rec_web_server.py cpu #for cpu user +python rec_web_server.py gpu #for gpu user #or -python rec_debugger_server.py +python rec_debugger_server.py cpu #for cpu user +python rec_debugger_server.py gpu #for gpu user ``` ### 识别服务客户端 diff --git a/python/examples/ocr/det_debugger_server.py b/python/examples/ocr/det_debugger_server.py index acfccdb6..78970af4 100644 --- a/python/examples/ocr/det_debugger_server.py +++ b/python/examples/ocr/det_debugger_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/python/examples/ocr/det_web_server.py b/python/examples/ocr/det_web_server.py index dd69be0c..14be7413 100644 --- a/python/examples/ocr/det_web_server.py +++ b/python/examples/ocr/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/python/examples/ocr/ocr_debugger_server.py b/python/examples/ocr/ocr_debugger_server.py index 93e2d7a3..f7458c30 100644 --- a/python/examples/ocr/ocr_debugger_server.py +++ b/python/examples/ocr/ocr_debugger_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/python/examples/ocr/ocr_web_server.py b/python/examples/ocr/ocr_web_server.py index d017f6b9..6c0de446 100644 --- a/python/examples/ocr/ocr_web_server.py +++ b/python/examples/ocr/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/python/examples/ocr/rec_web_server.py b/python/examples/ocr/rec_web_server.py index 684c313d..0f4e9f6d 100644 --- a/python/examples/ocr/rec_web_server.py +++ b/python/examples/ocr/rec_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 @@ -64,8 +67,11 @@ class OCRService(WebService): ocr_service = OCRService(name="ocr") ocr_service.load_model_config("ocr_rec_model") -ocr_service.set_gpus("0") ocr_service.init_rec() -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.run_rpc_service() ocr_service.run_web_service() -- GitLab