未验证 提交 5a43eba9 编写于 作者: B Bin Long 提交者: GitHub

Merge pull request #224 from ShenYuhan/update_file

update serving demo, add notes
......@@ -3,9 +3,12 @@ import requests
import json
if __name__ == "__main__":
# 指定要预测的图片并生成列表[("image", img_1), ("image", img_2), ... ]
file_list = ["../img/cat.jpg", "../img/flower.jpg"]
files = [("image", (open(item, "rb"))) for item in file_list]
# 指定预测方法为vgg11_imagenet并发送post请求
url = "http://127.0.0.1:8866/predict/image/vgg11_imagenet"
r = requests.post(url=url, files=files)
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -5,14 +5,17 @@ import base64
import os
if __name__ == "__main__":
# 指定要使用的图片文件并生成列表[("image", img_1), ("image", img_2), ... ]
file_list = ["../img/woman.png"]
files = [("image", (open(item, "rb"))) for item in file_list]
url = "http://127.0.0.1:8866/predict/image/stgan_celeba"
# 为每张图片对应指定info和style
data = {"info": ["Female,Brown_Hair"], "style": ["Aged"]}
# 指定图片生成方法为stgan_celeba并发送post请求
url = "http://127.0.0.1:8866/predict/image/stgan_celeba"
r = requests.post(url=url, data=data, files=files)
results = eval(r.json()["results"])
# 保存生成的图片到output文件夹,打印模型输出结果
if not os.path.exists("output"):
os.mkdir("output")
for item in results:
......
......@@ -3,12 +3,15 @@ import requests
import json
if __name__ == "__main__":
# 指定用于用于预测的文本并生成字典{"text": [text_1, text_2, ... ]}
text_list = [
"the plant which is owned by <unk> & <unk> co. was under contract with <unk> to make the cigarette filter",
"more common <unk> fibers are <unk> and are more easily rejected by the body dr. <unk> explained"
]
text = {"text": text_list}
# 指定预测方法为lm_lstm并发送post请求
url = "http://127.0.0.1:8866/predict/text/lm_lstm"
r = requests.post(url=url, data=text)
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -3,9 +3,12 @@ import requests
import json
if __name__ == "__main__":
# 指定用于用于预测的文本并生成字典{"text": [text_1, text_2, ... ]}
text_list = ["今天是个好日子", "天气预报说今天要下雨"]
text = {"text": text_list}
# 指定预测方法为lac并发送post请求
url = "http://127.0.0.1:8866/predict/text/lac"
r = requests.post(url=url, data=text)
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -3,11 +3,14 @@ import requests
import json
if __name__ == "__main__":
# 指定用于用于预测的文本并生成字典{"text": [text_1, text_2, ... ]}
text_list = ["今天是个好日子", "天气预报说今天要下雨"]
text = {"text": text_list}
# 将用户自定义词典文件发送到预测接口即可
# 指定自定义词典{"user_dict": dict.txt}
file = {"user_dict": open("dict.txt", "rb")}
# 指定预测方法为lac并发送post请求
url = "http://127.0.0.1:8866/predict/text/lac"
r = requests.post(url=url, files=file, data=text)
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -5,13 +5,16 @@ import base64
import os
if __name__ == "__main__":
# 指定要检测的图片并生成列表[("image", img_1), ("image", img_2), ... ]
file_list = ["../img/cat.jpg", "../img/dog.jpg"]
files = [("image", (open(item, "rb"))) for item in file_list]
# 指定检测方法为yolov3_coco2017并发送post请求
url = "http://127.0.0.1:8866/predict/image/yolov3_coco2017"
r = requests.post(url=url, files=files)
results = eval(r.json()["results"])
# 保存检测生成的图片到output文件夹,打印模型输出结果
if not os.path.exists("output"):
os.mkdir("output")
for item in results:
......
......@@ -3,11 +3,15 @@ import requests
import json
if __name__ == "__main__":
# 指定用于用于匹配的文本并生成字典{"text_1": [text_a1, text_a2, ... ]
# "text_2": [text_b1, text_b2, ... ]}
text = {
"text_1": ["这道题太难了", "这道题太难了", "这道题太难了"],
"text_2": ["这道题是上一年的考题", "这道题不简单", "这道题很有意思"]
}
# 指定匹配方法为simnet_bow并发送post请求
url = "http://127.0.0.1:8866/predict/text/simnet_bow"
r = requests.post(url=url, data=text)
# 打印匹配结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -5,13 +5,16 @@ import base64
import os
if __name__ == "__main__":
# 指定要使用的图片文件并生成列表[("image", img_1), ("image", img_2), ... ]
file_list = ["../img/girl.jpg"]
files = [("image", (open(item, "rb"))) for item in file_list]
# 指定图片分割方法为deeplabv3p_xception65_humanseg并发送post请求
url = "http://127.0.0.1:8866/predict/image/deeplabv3p_xception65_humanseg"
r = requests.post(url=url, files=files)
results = eval(r.json()["results"])
# 保存分割后的图片到output文件夹,打印模型输出结果
if not os.path.exists("output"):
os.mkdir("output")
for item in results:
......
......@@ -3,9 +3,12 @@ import requests
import json
if __name__ == "__main__":
# 指定用于用于预测的文本并生成字典{"text": [text_1, text_2, ... ]}
text_list = ["我不爱吃甜食", "我喜欢躺在床上看电影"]
text = {"text": text_list}
# 指定预测方法为senta_lstm并发送post请求
url = "http://127.0.0.1:8866/predict/text/senta_lstm"
r = requests.post(url=url, data=text)
# 打印预测结果
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
......@@ -287,7 +287,10 @@ class CacheUpdater(threading.Thread):
"command": "update_cache",
"mtime": os.stat(cache_path).st_mtime
}
r = srv_utils.hub_request(api_url, payload, extra)
try:
r = srv_utils.hub_request(api_url, payload, extra)
except Exception as err:
pass
if r.get("update_cache", 0) == 1:
with open(cache_path, 'w+') as fp:
yaml.safe_dump({'resource_list': r['data']}, fp)
......
......@@ -128,6 +128,8 @@ class Module(object):
elif module_dir:
self._init_with_module_file(module_dir=module_dir[0])
lock.flock(fp_lock, lock.LOCK_UN)
name = module_dir[0].split("/")[-1]
version = module_dir[1]
elif signatures:
if processor:
if not issubclass(processor, BaseProcessor):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册