From 5e3ca2d53e49e3d0914159accd501c7f6e25b900 Mon Sep 17 00:00:00 2001 From: buchongyu <18001307871@163.com> Date: Wed, 13 Jul 2022 14:15:18 +0800 Subject: [PATCH] fix deeplabv3p_xception65_humanseg inference client bug (#1914) --- .../deeplabv3p_xception65_humanseg/README.md | 57 ++++++++++--------- .../README_en.md | 57 ++++++++++--------- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md b/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md index 4b939565..ae623197 100644 --- a/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md +++ b/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md @@ -131,34 +131,35 @@ - 配置好服务端,以下数行代码即可实现发送预测请求,获取预测结果 - ```python - import requests - import json - import cv2 - import base64 - import numpy as np - - - def cv2_to_base64(image): - data = cv2.imencode('.jpg', image)[1] - return base64.b64encode(data.tostring()).decode('utf8') - - - def base64_to_cv2(b64str): - data = base64.b64decode(b64str.encode('utf8')) - data = np.fromstring(data, np.uint8) - data = cv2.imdecode(data, cv2.IMREAD_COLOR) - return data - - # 发送HTTP请求 - data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]} - headers = {"Content-type": "application/json"} - url = "http://127.0.0.1:8866/predict/deeplabv3p_xception65_humanseg" - r = requests.post(url=url, headers=headers, # 保存图片 - mask =cv2.cvtColor(base64_to_cv2(r.json()["results"][0]['data']), cv2.COLOR_BGR2GRAY) - rgba = np.concatenate((org_im, np.expand_dims(mask, axis=2)), axis=2) - cv2.imwrite("segment_human_server.png", rgba) - ``` + - ```python + import requests + import json + import cv2 + import base64 + import numpy as np + + + def cv2_to_base64(image): + data = cv2.imencode('.jpg', image)[1] + return base64.b64encode(data.tostring()).decode('utf8') + + + def base64_to_cv2(b64str): + data = base64.b64decode(b64str.encode('utf8')) + data = np.fromstring(data, np.uint8) + data = cv2.imdecode(data, cv2.IMREAD_COLOR) + return data + + org_im = cv2.imread("/PATH/TO/IMAGE") + # 发送HTTP请求 + data = {'images':[cv2_to_base64(org_im)]} + headers = {"Content-type": "application/json"} + url = "http://127.0.0.1:8866/predict/deeplabv3p_xception65_humanseg" + r = requests.post(url=url, headers=headers, data=json.dumps(data))# 保存图片 + mask =cv2.cvtColor(base64_to_cv2(r.json()["results"][0]['data']), cv2.COLOR_BGR2GRAY) + rgba = np.concatenate((org_im, np.expand_dims(mask, axis=2)), axis=2) + cv2.imwrite("segment_human_server.png", rgba) + ``` ## 五、更新历史 diff --git a/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md b/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md index eb6204c7..8e090c7f 100644 --- a/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md +++ b/modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md @@ -128,34 +128,35 @@ - With a configured server, use the following lines of code to send the prediction request and obtain the result - - ```python - import requests - import json - import cv2 - import base64 - import numpy as np - - - def cv2_to_base64(image): - data = cv2.imencode('.jpg', image)[1] - return base64.b64encode(data.tostring()).decode('utf8') - - - def base64_to_cv2(b64str): - data = base64.b64decode(b64str.encode('utf8')) - data = np.fromstring(data, np.uint8) - data = cv2.imdecode(data, cv2.IMREAD_COLOR) - return data - - # Send an HTTP request - data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]} - headers = {"Content-type": "application/json"} - url = "http://127.0.0.1:8866/predict/deeplabv3p_xception65_humanseg" - r = requests.post(url=url, headers=headers, - mask =cv2.cvtColor(base64_to_cv2(r.json()["results"][0]['data']), cv2.COLOR_BGR2GRAY) - rgba = np.concatenate((org_im, np.expand_dims(mask, axis=2)), axis=2) - cv2.imwrite("segment_human_server.png", rgba) - ``` + - ```python + import requests + import json + import cv2 + import base64 + import numpy as np + + + def cv2_to_base64(image): + data = cv2.imencode('.jpg', image)[1] + return base64.b64encode(data.tostring()).decode('utf8') + + + def base64_to_cv2(b64str): + data = base64.b64decode(b64str.encode('utf8')) + data = np.fromstring(data, np.uint8) + data = cv2.imdecode(data, cv2.IMREAD_COLOR) + return data + + org_im = cv2.imread("/PATH/TO/IMAGE") + # Send an HTTP request + data = {'images':[cv2_to_base64(org_im)]} + headers = {"Content-type": "application/json"} + url = "http://127.0.0.1:8866/predict/deeplabv3p_xception65_humanseg" + r = requests.post(url=url, headers=headers, data=json.dumps(data)) + mask =cv2.cvtColor(base64_to_cv2(r.json()["results"][0]['data']), cv2.COLOR_BGR2GRAY) + rgba = np.concatenate((org_im, np.expand_dims(mask, axis=2)), axis=2) + cv2.imwrite("segment_human_server.png", rgba) + ``` ## V. Release Note - 1.0.0 -- GitLab