提交 c4bfd68e 编写于 作者: M MRXLT

senta demo support batch

上级 8595b835
...@@ -30,10 +30,6 @@ class SentaService(WebService): ...@@ -30,10 +30,6 @@ class SentaService(WebService):
self.lac_client_config_path = lac_model_path + "/serving_server_conf.prototxt" self.lac_client_config_path = lac_model_path + "/serving_server_conf.prototxt"
self.lac_dict_path = lac_dict_path self.lac_dict_path = lac_dict_path
self.senta_dict_path = senta_dict_path self.senta_dict_path = senta_dict_path
self.show = False
def show_detail(self, show=False):
self.show = show
def start_lac_service(self): def start_lac_service(self):
if not os.path.exists('./lac_serving'): if not os.path.exists('./lac_serving'):
...@@ -67,28 +63,23 @@ class SentaService(WebService): ...@@ -67,28 +63,23 @@ class SentaService(WebService):
self.senta_reader = SentaReader() self.senta_reader = SentaReader()
def preprocess(self, feed=[], fetch=[]): def preprocess(self, feed=[], fetch=[]):
feed_data = self.lac_reader.process(feed[0]["words"]) feed_data = [{
if self.show: "words": self.lac_reader.process(x["words"])
print("---- lac reader ----") } for x in feed]
print(feed_data) lac_result = self.lac_client.predict(
lac_result = self.lac_predict(feed_data) feed=feed_data, fetch=["crf_decode"])
if self.show: feed_batch = []
print("---- lac out ----") result_lod = lac_result["crf_decode.lod"]
print(lac_result) for i in range(len(feed)):
segs = self.lac_reader.parse_result(feed[0]["words"], segs = self.lac_reader.parse_result(
lac_result["crf_decode"]) feed[i]["words"],
if self.show: lac_result["crf_decode"][result_lod[i]:result_lod[i + 1]])
print("---- lac parse ----") feed_data = self.senta_reader.process(segs)
print(segs) feed_batch.append({"words": feed_data})
feed_data = self.senta_reader.process(segs) return feed_batch, fetch
if self.show:
print("---- senta reader ----")
print("feed_data", feed_data)
return [{"words": feed_data}], fetch
senta_service = SentaService(name="senta") senta_service = SentaService(name="senta")
senta_service.show_detail(False)
senta_service.set_config( senta_service.set_config(
lac_model_path="./lac_model", lac_model_path="./lac_model",
lac_dict_path="./lac_dict", lac_dict_path="./lac_dict",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册