我有一点令人困惑。下面是示例代码:
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)
输出为:conv1/filt conv1/bias
当我将 var.op.name
更改为 var.name
输出为:conv1/filt:0 conv1/bias:0
var.op.name
和 var.name
有什么区别?
:0
是什么意思?
最佳答案
op.name
是操作的名称,而 var.name
是张量的名称。操作是分配内存并在端点 :0、:1 等上产生可用输出的东西。张量是操作的输出,因此它对应于某个端点。在本例中,conv1/filt
是负责内存的变量操作,conv1/filt:0
是该操作的第一个端点。实际的区别在于,您可以通过 conv1/filt:0
获取值,即 sess.run(["conv1/filt:0"])
,当您使用 conv1/filt
来获取操作时,即 tf.get_default_graph().get_operation_by_name("conv1/filt")
关于python - tensorflow 中的 var.op.name 和 var.name 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240050/