Skip to content

Commit

Permalink
Merge pull request #839 from MRXLT/release/0.3
Browse files Browse the repository at this point in the history
[cherry pick to 0.3.2] debugger predict && bug fix
  • Loading branch information
MRXLT authored Sep 15, 2020
2 parents 48f7e4f + 724d99a commit 6916c8b
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmake/paddlepaddle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message( "WITH_GPU = ${WITH_GPU}")
# Paddle Version should be one of:
# latest: latest develop build
# version number like 1.5.2
SET(PADDLE_VERSION "1.7.2")
SET(PADDLE_VERSION "1.8.4")

if (WITH_GPU)
SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-gpu-cuda${CUDA_VERSION_MAJOR}-cudnn7-avx-mkl")
Expand Down
2 changes: 1 addition & 1 deletion python/examples/ocr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Dataset: RCTW 500 sample images
| Serving web service | 8.69 | 13.41 | 109.97 | 2.82 | 87.76 | 4.29 | 3.98 | 78.51 | 3.66 | 4.12 | 181.02 | 136.49 | 317.51 |
| Serving Debugger web service | 8.73 | 16.42 | 115.27 | 2.93 | 20.63 | 3.97 | 4.48 | 13.84 | 3.60 | 6.91 | 49.45 | 147.33 | 196.78 |

## Appendix: Det or Rec only
## Appendix: For Users who want to launch Det or Rec only
if you are going to detect images not recognize it or directly recognize the words from images. We also provide Det and Rec server for you.

### Det Server
Expand Down
5 changes: 3 additions & 2 deletions python/examples/ocr/det_debugger_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from paddle_serving_app.reader import DBPostProcess, FilterBoxes
if sys.argv[1] == 'gpu':
from paddle_serving_server_gpu.web_service import WebService
elif sys.argv[1] == 'cpu'
elif sys.argv[1] == 'cpu':
from paddle_serving_server.web_service import WebService
import time
import re
Expand Down Expand Up @@ -69,7 +69,8 @@ def postprocess(self, feed={}, fetch=[], fetch_map=None):
ocr_service.load_model_config("ocr_det_model")
if sys.argv[1] == 'gpu':
ocr_service.set_gpus("0")
ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=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()
Expand Down
3 changes: 2 additions & 1 deletion python/examples/ocr/det_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def postprocess(self, feed={}, fetch=[], fetch_map=None):
ocr_service.load_model_config("ocr_det_model")
if sys.argv[1] == 'gpu':
ocr_service.set_gpus("0")
ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=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()
Expand Down
3 changes: 2 additions & 1 deletion python/examples/ocr/ocr_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def postprocess(self, feed={}, fetch=[], fetch_map=None):
ocr_service.load_model_config("ocr_rec_model")
if sys.argv[1] == 'gpu':
ocr_service.set_gpus("0")
ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=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(
Expand Down
3 changes: 2 additions & 1 deletion python/examples/ocr/rec_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def postprocess(self, feed={}, fetch=[], fetch_map=None):
ocr_service.init_rec()
if sys.argv[1] == 'gpu':
ocr_service.set_gpus("0")
ocr_service.prepare_server(workdir="workdir", port=9292, device="gpu", gpuid=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()
Expand Down
4 changes: 2 additions & 2 deletions python/paddle_serving_app/reader/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _bbox2out(self, results, clsid2catid, is_bbox_normalized=False):
self.clip_bbox([xmin, ymin, xmax, ymax])
w = xmax - xmin
h = ymax - ymin
im_shape = t['im_shape'][0][i].tolist()
im_shape = t['im_shape'].tolist()
im_height, im_width = int(im_shape[0]), int(im_shape[1])
xmin *= im_width
ymin *= im_height
Expand Down Expand Up @@ -420,7 +420,7 @@ def __call__(self, image_with_bbox):
for key in image_with_bbox:
if key == "image":
continue
if ".lod" in key:
if ".lod" in key or "im_shape" in key:
continue
fetch_name = key
bbox_result = self._get_bbox_result(image_with_bbox, fetch_name,
Expand Down
28 changes: 28 additions & 0 deletions python/paddle_serving_server/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def get_prediction(self, request):
request.json["fetch"])
if isinstance(feed, dict) and "fetch" in feed:
del feed["fetch"]
if len(feed) == 0:
raise ValueError("empty input")
fetch_map = self.client.predict(feed=feed, fetch=fetch)
result = self.postprocess(
feed=request.json["feed"], fetch=fetch, fetch_map=fetch_map)
Expand Down Expand Up @@ -122,6 +124,32 @@ def run():

self.app_instance = app_instance

def run_debugger_service(self):
import socket
localIP = socket.gethostbyname(socket.gethostname())
print("web service address:")
print("http://{}:{}/{}/prediction".format(localIP, self.port,
self.name))
app_instance = Flask(__name__)

@app_instance.before_first_request
def init():
self._launch_local_predictor()

service_name = "/" + self.name + "/prediction"

@app_instance.route(service_name, methods=["POST"])
def run():
return self.get_prediction(request)

self.app_instance = app_instance

def _launch_local_predictor(self):
from paddle_serving_app.local_predict import Debugger
self.client = Debugger()
self.client.load_model_config(
"{}".format(self.model_config), gpu=False, profile=False)

def run_web_service(self):
self.app_instance.run(host="0.0.0.0",
port=self.port,
Expand Down
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numpy>=1.12, <=1.16.4 ; python_version<"3.5"
google>=2.0.3
opencv-python==4.2.0.32
protobuf>=3.12.2
grpcio-tools>=1.28.1
grpcio>=1.28.1
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py.app.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if '${PACK}' == 'ON':


REQUIRED_PACKAGES = [
'six >= 1.10.0', 'sentencepiece', 'opencv-python', 'pillow',
'six >= 1.10.0', 'sentencepiece', 'opencv-python<=4.2.0.32', 'pillow',
'shapely', 'pyclipper'
]

Expand Down

0 comments on commit 6916c8b

Please sign in to comment.