From 6ddd8049e0c2393f7dd3b98baa93ca79dca58699 Mon Sep 17 00:00:00 2001 From: Tingquan Gao Date: Thu, 17 Dec 2020 15:23:29 +0800 Subject: [PATCH] Add "cpu_num_threads" and "enable_profile" (#494) --- deploy/hubserving/clas/params.py | 2 ++ tools/test_hubserving.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/deploy/hubserving/clas/params.py b/deploy/hubserving/clas/params.py index a7af70d9..83224f59 100644 --- a/deploy/hubserving/clas/params.py +++ b/deploy/hubserving/clas/params.py @@ -33,6 +33,8 @@ def read_params(): cfg.gpu_mem = 8000 cfg.use_fp16 = False cfg.use_tensorrt = False + cfg.cpu_num_threads = 10 + cfg.enable_profile = False # params for preprocess cfg.resize_short = 256 diff --git a/tools/test_hubserving.py b/tools/test_hubserving.py index 08ddccc2..bd0d1179 100644 --- a/tools/test_hubserving.py +++ b/tools/test_hubserving.py @@ -57,19 +57,27 @@ def main(url, image_path, top_k=1): all_acc = 0.0 for image_file in image_file_list: + file_str = image_file.split('/')[-1] img = open(image_file, 'rb').read() if img is None: - logger.info("error in loading image:{}".format(image_file)) + logger.error("Loading image:{} failed".format(image_file)) continue data = {'images': [cv2_to_base64(img)], 'top_k': top_k} starttime = time.time() - r = requests.post(url=url, headers=headers, data=json.dumps(data)) - assert r.status_code == 200, "Request error, status_code: {}".format( - r.status_code) + try: + r = requests.post(url=url, headers=headers, data=json.dumps(data)) + r.raise_for_status() + except Exception as e: + logger.error("File:{}, {}".format(file_str, e)) + continue elapse = time.time() - starttime total_time += elapse - + if r.json()['status'] != '0': + logger.error( + "File:{}, The parameters returned by the server are: {}". + format(file_str, r.json()['msg'])) + continue res = r.json()["results"][0] classes = res[0] scores = res[1] @@ -79,7 +87,6 @@ def main(url, image_path, top_k=1): scores = map(lambda x: round(x, 5), scores) results = dict(zip(classes, scores)) - file_str = image_file.split('/')[-1] message = "No.{}, File:{}, The top-{} result(s):{}, Time cost:{:.3f}".format( cnt, file_str, top_k, results, elapse) logger.info(message) -- GitLab