未验证 提交 e1e5c19e 编写于 作者: W will-jl944 提交者: GitHub

compatible with paddlex 2.0 (#1628)

上级 22869545
......@@ -14,17 +14,30 @@ from paddlehub.module.module import moduleinfo, runnable, serving
def base64_to_cv2(b64str):
data = base64.b64decode(b64str.encode('utf8'))
data = np.fromstring(data, np.uint8)
data = np.frombuffer(data, np.uint8)
data = cv2.imdecode(data, cv2.IMREAD_COLOR)
return data
def base64_to_np(b64tuple):
data, shape = b64tuple
data = base64.b64decode(data.encode('utf8'))
data = np.frombuffer(data, np.float32).reshape(shape)
return data
def cv2_to_base64(image):
# return base64.b64encode(image)
data = cv2.imencode('.jpg', image)[1]
return base64.b64encode(data.tostring()).decode('utf8')
def np_to_base64(array):
shape = array.shape
data = base64.b64encode(array).decode('utf8')
return data, shape
def read_images(paths):
images = []
for path in paths:
......@@ -83,7 +96,9 @@ class MODULE(hub.Module):
if isinstance(result, dict):
# result_new = dict()
for key, value in result.items():
if isinstance(value, np.ndarray):
if key == 'score_map':
result[key] = np_to_base64(value)
elif isinstance(value, np.ndarray):
result[key] = cv2_to_base64(value)
elif isinstance(value, np.generic):
result[key] = np.asscalar(value)
......@@ -91,7 +106,9 @@ class MODULE(hub.Module):
elif isinstance(result, list):
for index in range(len(result)):
for key, value in result[index].items():
if isinstance(value, np.ndarray):
if key == 'score_map':
result[index][key] = np_to_base64(value)
elif isinstance(value, np.ndarray):
result[index][key] = cv2_to_base64(value)
elif isinstance(value, np.generic):
result[index][key] = np.asscalar(value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册