make_tensor_proto(values, dtype=None, shape=None)Creates TensorProto object from values.
Args:
-
values: Values to put in theTensorProto. The accepted types are: python scalar, pythons list, numpy scalar and numpy ndarray. Python scalars and lists are internally converted to their numpy counterparts before further processing. Bytes values are placed inTensorProtostring_val field. -
dtype(optional): tensor_pb2 DataType value. If not provided, the function will try to infer the data type from values argument. -
shape(optional): The list or tuple of integers defining the shape of the tensor. If not provided, the function will try to infer the shape from values argument.
Returns: TensorProto object filled with values.
Raises:
TypeError: if unsupported types are provided.ValueError: if arguments have inappropriate values.
Examples:
# With python list
data = [[1, 2, 3], [4, 5, 6]]
tensor_proto = make_tensor_proto(data)
# With numpy array:
data = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
tensor_proto = make_tensor_proto(data)
# With binary data:
with open("image.jpg", "rb") as f:
data = f.read()
tensor_proto = make_tensor_proto(data)