提交 878d3e7d 编写于 作者: M MRXLT

http service support batch

上级 508997bb
......@@ -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
```
......@@ -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
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册