diff --git a/python/examples/pipeline/imagenet/benchmark.py b/python/examples/pipeline/imagenet/benchmark.py index f96d25350fb155140ea5279c802cb7b929e5a12f..22c1ce873f2db2d866a96ff9a68ffce3bd5b98f5 100644 --- a/python/examples/pipeline/imagenet/benchmark.py +++ b/python/examples/pipeline/imagenet/benchmark.py @@ -46,11 +46,16 @@ def run_http(idx, batch_size): with open(os.path.join(".", "daisy.jpg"), 'rb') as file: image_data1 = file.read() 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() while True: 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 end = time.time() return [[end - start]] diff --git a/python/examples/pipeline/imagenet/resnet50_web_service.py b/python/examples/pipeline/imagenet/resnet50_web_service.py index 635636cdd3f139065128c4a013d7999c223d87ec..11fa1ab14181fca1833cbbe6c9bb89afa9531b3f 100644 --- a/python/examples/pipeline/imagenet/resnet50_web_service.py +++ b/python/examples/pipeline/imagenet/resnet50_web_service.py @@ -38,15 +38,19 @@ class ImagenetOp(Op): def preprocess(self, input_dicts, data_id, log_id): (_, input_dict), = input_dicts.items() - data = base64.b64decode(input_dict["image"].encode('utf8')) - data = np.fromstring(data, np.uint8) - # Note: class variables(self.var) can only be used in process op mode - im = cv2.imdecode(data, cv2.IMREAD_COLOR) - img = self.seq(im) - return {"image": img[np.newaxis, :].copy()}, False, None, "" + batch_size = len(input_dict.keys()) + imgs = [] + for key in input_dict.keys(): + data = base64.b64decode(input_dict[key].encode('utf8')) + data = np.fromstring(data, np.uint8) + 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): - score_list = fetch_dict["score"] + score_list = fetch_dict["prediction"] result = {"label": [], "prob": []} for score in score_list: score = score.tolist()