提交 164aa758 编写于 作者: G guru4elephant

update web service

上级 3e681505
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
import paddlehub as hub import paddlehub as hub
import paddle.fluid as fluid import paddle.fluid as fluid
import sys
import paddle_serving_client.io as serving_io import paddle_serving_client.io as serving_io
model_name = "bert_chinese_L-12_H-768_A-12" model_name = "bert_chinese_L-12_H-768_A-12"
module = hub.Module(model_name) module = hub.Module(model_name)
inputs, outputs, program = module.context(trainable=True, max_seq_len=20) inputs, outputs, program = module.context(trainable=True, max_seq_len=int(sys.argv[1]))
place = fluid.core_avx.CPUPlace() place = fluid.core_avx.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
input_ids = inputs["input_ids"] input_ids = inputs["input_ids"]
...@@ -34,7 +35,7 @@ feed_var_names = [ ...@@ -34,7 +35,7 @@ feed_var_names = [
target_vars = [pooled_output, sequence_output] target_vars = [pooled_output, sequence_output]
serving_io.save_model("serving_server_model", "serving_client_conf", { serving_io.save_model("bert_seq{}_model".format(sys.argv[1]), "bert_seq{}_client".format(sys.argv[1]), {
"input_ids": input_ids, "input_ids": input_ids,
"position_ids": position_ids, "position_ids": position_ids,
"segment_ids": segment_ids, "segment_ids": segment_ids,
......
...@@ -60,6 +60,8 @@ class WebService(object): ...@@ -60,6 +60,8 @@ class WebService(object):
if "fetch" not in request.json: if "fetch" not in request.json:
abort(400) abort(400)
feed, fetch = self.preprocess(request.json, request.json["fetch"]) feed, fetch = self.preprocess(request.json, request.json["fetch"])
if "fetch" in feed:
del feed["fetch"]
fetch_map = client_service.predict(feed=feed, fetch=fetch) fetch_map = client_service.predict(feed=feed, fetch=fetch)
fetch_map = self.postprocess(feed=request.json, fetch=fetch, fetch_map=fetch_map) fetch_map = self.postprocess(feed=request.json, fetch=fetch, fetch_map=fetch_map)
return fetch_map return fetch_map
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册