karl_TUM karl_TUM - 4 months ago 28
Python Question

what is the difference between var.op.name and var.name in tensorflow?

I have one point confusing. Here is the example code:

opt = tf.train.GradientDescentOptimizer(1e-4)
grads_and_vars = opt.compute_gradients(total_loss)
for grad, var in grads_and_vars:
print(var.op.name)


the output is:
conv1/filt conv1/bias


and when I change
var.op.name
into
var.name


the output is:
conv1/filt:0 conv1/bias:0


What is the difference between
var.op.name
and
var.name
?
and what does
:0
mean?

Answer

"op.name" is the name of the Operation, while "var.name" is the name of the Tensor. Operation is the thing that allocates memory, and produces outputs available on endpoints :0, :1, etc. Tensor is an output of an operation, so it corresponds to some endpoint. In this case conv1/filt is the Variable Operation that is in charge of the memory, and conv1/filt:0 is the first endpoint of that operation. The practical difference is that conv1/filt:0 is what you can fetch to get the value, ie sess.run(["conv1/filt:0"])

Comments