Source: model_server/utils/tensor_utils.py#L0
create_tensor_proto
create_tensor_proto(array, shape=None, dtype=None, name=None)
Create a TensorProto from numpy array.
Arguments:
- array (np.ndarray): The numpy array to convert to TensorProto
- shape (tuple): Optional shape of the array to reshape it to. If not given, it is inferred from the numpy array. Default None
- dtype (str): Optional dtype to convert the array to. Refer tensor.proto for supported datatypes. If not given, it is inferred from the numpy array. Default None.
- name (str): Optional name for the TensorProto. Default None
Returns:
A TensorProto containing the given array
Note:
- python strings will be encoded to python bytes.
- Use dtype = "object" if the numpy array contains strings.
- dtype "string" and "object" are treated as same.
- "string" is converted to python "object". This is because, numpy handles variable length strings in this way
create_array_from_proto
create_array_from_proto(tensor_proto)
Retrive array from TensorProto.
Arguments:
- tensor_proto (TensorProto): An instance of TensorProto
Returns:
numpy array
Note:
- python strings will be encoded to python bytes.
- Use dtype = "object" if the numpy array contains strings.
- dtype "string" and "object" are treated as same.
- "string" is converted to python "object". This is because, numpy handles variable length strings in this way