提交 317ac989 编写于 作者: R root

support bs>1

上级 feb46a7d
...@@ -46,11 +46,16 @@ def run_http(idx, batch_size): ...@@ -46,11 +46,16 @@ def run_http(idx, batch_size):
with open(os.path.join(".", "daisy.jpg"), 'rb') as file: with open(os.path.join(".", "daisy.jpg"), 'rb') as file:
image_data1 = file.read() image_data1 = file.read()
image = cv2_to_base64(image_data1) image = cv2_to_base64(image_data1)
data = {"key": ["image"], "value": [image]} keys, values = [], []
for i in range(batch_size):
keys.append("image_{}".format(i))
values.append(image)
data = {"key": keys, "value": values}
start_time = time.time() start_time = time.time()
while True: while True:
r = requests.post(url=url, data=json.dumps(data)) r = requests.post(url=url, data=json.dumps(data))
if time.time() - start_time > 10: print(r.json())
if time.time() - start_time > 20:
break break
end = time.time() end = time.time()
return [[end - start]] return [[end - start]]
......
...@@ -38,15 +38,19 @@ class ImagenetOp(Op): ...@@ -38,15 +38,19 @@ class ImagenetOp(Op):
def preprocess(self, input_dicts, data_id, log_id): def preprocess(self, input_dicts, data_id, log_id):
(_, input_dict), = input_dicts.items() (_, input_dict), = input_dicts.items()
data = base64.b64decode(input_dict["image"].encode('utf8')) batch_size = len(input_dict.keys())
data = np.fromstring(data, np.uint8) imgs = []
# Note: class variables(self.var) can only be used in process op mode for key in input_dict.keys():
im = cv2.imdecode(data, cv2.IMREAD_COLOR) data = base64.b64decode(input_dict[key].encode('utf8'))
img = self.seq(im) data = np.fromstring(data, np.uint8)
return {"image": img[np.newaxis, :].copy()}, False, None, "" im = cv2.imdecode(data, cv2.IMREAD_COLOR)
img = self.seq(im)
imgs.append(img[np.newaxis, :].copy())
input_imgs = np.concatenate(imgs, axis=0)
return {"image": input_imgs}, False, None, ""
def postprocess(self, input_dicts, fetch_dict, log_id): def postprocess(self, input_dicts, fetch_dict, log_id):
score_list = fetch_dict["score"] score_list = fetch_dict["prediction"]
result = {"label": [], "prob": []} result = {"label": [], "prob": []}
for score in score_list: for score in score_list:
score = score.tolist() score = score.tolist()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册