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

Merge pull request #224 from ShenYuhan/update_file

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