From 878d3e7dbc98e7fc5e81527d67a2729727715faf Mon Sep 17 00:00:00 2001 From: MRXLT Date: Fri, 24 Apr 2020 18:27:14 +0800 Subject: [PATCH] http service support batch --- python/examples/fit_a_line/README.md | 2 +- python/paddle_serving_server/web_service.py | 11 ++++++----- python/paddle_serving_server_gpu/web_service.py | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/python/examples/fit_a_line/README.md b/python/examples/fit_a_line/README.md index 8ea146e9..acc51938 100644 --- a/python/examples/fit_a_line/README.md +++ b/python/examples/fit_a_line/README.md @@ -46,5 +46,5 @@ python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --po ### Client prediction ``` shell -curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' http://127.0.0.1:9393/uci/prediction +curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' http://127.0.0.1:9393/uci/prediction ``` diff --git a/python/paddle_serving_server/web_service.py b/python/paddle_serving_server/web_service.py index 4a033cbc..56cbd976 100755 --- a/python/paddle_serving_server/web_service.py +++ b/python/paddle_serving_server/web_service.py @@ -61,14 +61,15 @@ class WebService(object): if "fetch" not in request.json: abort(400) try: - feed, fetch = self.preprocess(request.json, request.json["fetch"]) + feed, fetch = self.preprocess(request.json["feed"], + request.json["fetch"]) if isinstance(feed, dict) and "fetch" in feed: del feed["fetch"] fetch_map = self.client_service.predict(feed=feed, fetch=fetch) for key in fetch_map: - fetch_map[key] = fetch_map[key][0].tolist() + fetch_map[key] = fetch_map[key].tolist() result = self.postprocess( - feed=request.json, fetch=fetch, fetch_map=fetch_map) + feed=feed, fetch=fetch, fetch_map=fetch_map) result = {"result": result} except ValueError: result = {"result": "Request Value Error"} @@ -83,8 +84,8 @@ class WebService(object): p_rpc = Process(target=self._launch_rpc_service) p_rpc.start() - def preprocess(self, feed={}, fetch=[]): + def preprocess(self, feed=[], fetch=[]): return feed, fetch - def postprocess(self, feed={}, fetch=[], fetch_map=None): + def postprocess(self, feed=[], fetch=[], fetch_map=None): return fetch_map diff --git a/python/paddle_serving_server_gpu/web_service.py b/python/paddle_serving_server_gpu/web_service.py index cb833ba3..6482f9b2 100644 --- a/python/paddle_serving_server_gpu/web_service.py +++ b/python/paddle_serving_server_gpu/web_service.py @@ -105,14 +105,15 @@ class WebService(object): if "fetch" not in request.json: abort(400) try: - feed, fetch = self.preprocess(request.json, request.json["fetch"]) + feed, fetch = self.preprocess(request.json["feed"], + request.json["fetch"]) if isinstance(feed, dict) and "fetch" in feed: del feed["fetch"] fetch_map = self.client.predict(feed=feed, fetch=fetch) for key in fetch_map: - fetch_map[key] = fetch_map[key][0].tolist() + fetch_map[key] = fetch_map[key].tolist() result = self.postprocess( - feed=request.json, fetch=fetch, fetch_map=fetch_map) + feed=feed, fetch=fetch, fetch_map=fetch_map) result = {"result": result} except ValueError: result = {"result": "Request Value Error"} @@ -131,8 +132,8 @@ class WebService(object): for p in server_pros: p.start() - def preprocess(self, feed={}, fetch=[]): + def preprocess(self, feed=[], fetch=[]): return feed, fetch - def postprocess(self, feed={}, fetch=[], fetch_map=None): + def postprocess(self, feed=[], fetch=[], fetch_map=None): return fetch_map -- GitLab