TensorFlow – How to create a TensorProto
Last Updated :
01 Aug, 2020
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
TensorProto is mostly used to generate numpy array.
Function Used:
- make_tensor_proto: This function accepts values that need to be put in TensorProto with other optional arguments.
Example 1:
Python3
import tensorflow as tf
value = tf.constant([ 1 , 15 ], dtype = tf.float64)
print ( "Value: " , value)
res = tf.make_tensor_proto(value)
print ( "Result: " , res)
|
Output:
Value: tf.Tensor([ 1. 15.], shape=(2, ), dtype=float64)
Result: dtype: DT_DOUBLE
tensor_shape {
dim {
size: 2
}
}
tensor_content: "\000\000\000\000\000\000\360?\000\000\000\000\000\000.@"
Example 2: This example uses python array to generate TensorProto.
Python3
import tensorflow as tf
value = [ 1 , 2 , 3 , 4 ]
print ( "Value: " , value)
res = tf.make_tensor_proto(value)
print ( "Result: " , res)
|
Output:
Value: [1, 2, 3, 4]
Result: dtype: DT_INT32
tensor_shape {
dim {
size: 4
}
}
tensor_content: "\001\000\000\000\002\000\000\000\003\000\000\000\004\000\000\000"
Share your thoughts in the comments
Please Login to comment...