Open In App

TensorFlow - How to create a TensorProto

Last Updated : 01 Aug, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

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
# importing the library
import tensorflow as tf

# Initializing Input
value = tf.constant([1, 15], dtype = tf.float64)

# Printing the Input
print("Value: ", value)

# Getting TensorProto
res = tf.make_tensor_proto(value)

# Printing the resulting tensor
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
# importing the library
import tensorflow as tf

# Initializing Input
value = [1, 2, 3, 4]

# Printing the Input
print("Value: ", value)

# Getting TensorProto
res = tf.make_tensor_proto(value)

# Printing the resulting tensor
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"


Article Tags :
Practice Tags :

Similar Reads