提交 c28fbc69 编写于 作者: T TeslaZhao

python pipeline support lod input

上级 8df65d76
...@@ -1589,13 +1589,15 @@ class RequestOp(Op): ...@@ -1589,13 +1589,15 @@ class RequestOp(Op):
tensor: one tensor in request.tensors. tensor: one tensor in request.tensors.
Returns: Returns:
np.ndnumpy np_data: np.ndnumpy, the tensor data is converted to numpy.
lod_info: np.ndnumpy, lod info of the tensor data, None default.
""" """
if tensor is None or tensor.elem_type is None or tensor.name is None: if tensor is None or tensor.elem_type is None or tensor.name is None:
_LOGGER.error("input params of tensor is wrong. tensor: {}".format( _LOGGER.error("input params of tensor is wrong. tensor: {}".format(
tensor)) tensor))
return None return None
# Set dim shape
dims = [] dims = []
if tensor.shape is None: if tensor.shape is None:
dims.append(1) dims.append(1)
...@@ -1603,6 +1605,11 @@ class RequestOp(Op): ...@@ -1603,6 +1605,11 @@ class RequestOp(Op):
for one_dim in tensor.shape: for one_dim in tensor.shape:
dims.append(one_dim) dims.append(one_dim)
# Set up 2-d lod tensor
np_lod = None
if len(tensor.lod) > 0:
np_lod = np.array(tensor.lod).astype(int32).reshape(2, -1)
np_data = None np_data = None
_LOGGER.info("proto_to_numpy, name:{}, type:{}, dims:{}".format( _LOGGER.info("proto_to_numpy, name:{}, type:{}, dims:{}".format(
tensor.name, tensor.elem_type, dims)) tensor.name, tensor.elem_type, dims))
...@@ -1648,7 +1655,7 @@ class RequestOp(Op): ...@@ -1648,7 +1655,7 @@ class RequestOp(Op):
"Sorry, the type {} of tensor {} is not supported.".format( "Sorry, the type {} of tensor {} is not supported.".format(
tensor.elem_type, tensor.name)) tensor.elem_type, tensor.name))
return np_data return np_data, np_lod
def unpack_request_package(self, request): def unpack_request_package(self, request):
""" """
...@@ -1705,7 +1712,10 @@ class RequestOp(Op): ...@@ -1705,7 +1712,10 @@ class RequestOp(Op):
dict_data[name] = new_string dict_data[name] = new_string
else: else:
dict_data[name] = self.proto_tensor_2_numpy(one_tensor) np_data, np_lod = self.proto_tensor_2_numpy(one_tensor)
dict_data[name] = np_data
if np_lod is not None:
dict_data[name + ".lod"] = np_lod
_LOGGER.info("RequestOp unpack one request. log_id:{}, clientip:{} \ _LOGGER.info("RequestOp unpack one request. log_id:{}, clientip:{} \
name:{}, method:{}, time:{}" name:{}, method:{}, time:{}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册