Is there any way to assign a name to a tensor after it has been created?
I'm building up a neural network bit by bit in a loop, like so:
def build_logit_pipeline(data):
# X --> *W1 --> +b1 --> relu --> *W2 --> +b2 ... --> softmax etc...
pipeline = data
for i in xrange(len(layer_sizes) - 1):
with tf.name_scope("linear%d" % i):
pipeline = tf.matmul(pipeline, weights[i])
pipeline = tf.add(pipeline, biases[i])
if i != len(layer_sizes) - 2:
with tf.name_scope("relu%d" % i):
pipeline = tf.nn.relu(pipeline)
return pipeline
I'd like to assign a name to the result of the entire operation, i.e. the last tf.add
should be assigned a name. Is there a way to do this on the pipeline
variable right before returning, instead of checking the end of loop condition on the last add, which would be less elegant?
Tensors in Python Like vectors and matrices, tensors can be represented in Python using the N-dimensional array (ndarray). A tensor can be defined in-line to the constructor of array() as a list of lists. The example below defines a 3x3x3 tensor as a NumPy ndarray.
It is not possible to have a Tensor with more than one data type. It is possible, however, to serialize arbitrary data structures as strings and store those in tensors.
We can access the value of a tensor by using indexing and slicing. Indexing is used to access a single value in the tensor. slicing is used to access the sequence of values in a tensor. we can modify a tensor by using the assignment operator.
You cannot modify the name of a Tensor.
However, one easy trick to do what you want is to use tf.identity
with the name you want:
res = build_logit_pipeline(data)
res = tf.identity(res, name="your_name")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With