My goal is to convert a tensor into a ndarray without \'run\' or \'eval\'. I wanted to perform the same operation as the example.
tf.make_ndarray is used to convert TensorProto values into NumPy arrays. These values are generally the constants used in a graph. For example, when you use tf.constant, you create a Const
operation with an attribute value
holding the constant value that the operation will produce. That attribute is stored as a TensorProto. Hence, you can "extract" the value of a Const
operation as a NumPy array like this:
import tensorflow as tf
A = tf.constant(5)
C = tf.make_ndarray(A.op.get_attr('value'))
print(C, type(C))
# 5 <class 'numpy.ndarray'>
In general, though, you cannot convert arbitrary tensors into NumPy arrays, as their values will depend on the values of the variables and the fed inputs within a particular session.