diff --git a/python/pipeline/operator.py b/python/pipeline/operator.py index 6cdbbe50826cd722c7d7cdd81b1ec27cb798301b..cee5602788d752485e07a8d2a741c8f6cd29d6fc 100644 --- a/python/pipeline/operator.py +++ b/python/pipeline/operator.py @@ -19,6 +19,7 @@ from paddle_serving_client import MultiLangClient, Client from concurrent import futures import logging import func_timeout +from numpy import * from .proto import pipeline_service_pb2 from .channel import ThreadChannel, ProcessChannel, ChannelDataEcode, ChannelData, ChannelDataType @@ -391,7 +392,12 @@ class RequestOp(Op): def unpack_request_package(self, request): dictdata = {} for idx, key in enumerate(request.key): - dictdata[key] = request.value[idx] + data = request.value[idx] + try: + data = eval(data) + except Exception as e: + pass + dictdata[key] = data return dictdata diff --git a/python/pipeline/pipeline_client.py b/python/pipeline/pipeline_client.py index cf5e2e7758e458d55100ace47039dc17bb07677a..4ad05b5a953d5084ffda360c0a1ac561463898a4 100644 --- a/python/pipeline/pipeline_client.py +++ b/python/pipeline/pipeline_client.py @@ -35,10 +35,16 @@ class PipelineClient(object): def _pack_request_package(self, feed_dict): req = pipeline_service_pb2.Request() for key, value in feed_dict.items(): - if not isinstance(value, str): - raise TypeError("only str type is supported.") req.key.append(key) - req.value.append(value) + if isinstance(value, np.ndarray): + req.value.append(value.__repr__()) + elif isinstance(value, str): + req.value.append(value) + elif isinstance(value, list): + req.value.append(np.array(value).__repr__()) + else: + raise TypeError("only str and np.ndarray type is supported: {}". + format(type(value))) return req def _unpack_response_package(self, resp, fetch): @@ -50,7 +56,7 @@ class PipelineClient(object): continue data = resp.value[idx] try: - data = eval(resp.value[idx]) + data = eval(data) except Exception as e: pass fetch_map[key] = data