关于张量板亚当节点

时间:2017-04-11 12:14:01

标签: tensorflow tensorboard

当我运行tensorboard时,我在我的variable_scope中发现,例如'weight',有两个adam节点,其名称为'weight / Adam'和'weight / Adam_1',但我无法在我的variable_scope中定义'重量'。我的代码是错误的还是adam算法会自动在'weight'中添加两个节点以使控制依赖?

1 个答案:

答案 0 :(得分:0)

因此,首先,这2个节点由您的AdamOptimizer添加,作为BP计算图中的节点。

然后再问一个问题:为什么有两个节点而不是一个,以至于不了解幕后发生的事情,这应该是正常情况。试试这个简单的代码段:

import tensorflow as tf

x = tf.placeholder(shape=(None, 10), dtype=tf.float64)
W = tf.get_variable(shape=(10, 20), dtype=tf.float64, name="W")
y = tf.matmul(x, W)
opt = tf.train.AdamOptimizer(learning_rate=0.001, beta1=0.9, beta2=0.98, epsilon=1e-8)
y_true = tf.placeholder(shape=(None, 20), dtype=tf.float64)
loss = y_true - y
train_op = opt.minimize(loss)

for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES):
    print(v)

这将为您提供以下内容:

<tf.Variable 'W:0' shape=(10, 20) dtype=float64_ref>
<tf.Variable 'beta1_power:0' shape=() dtype=float32_ref>
<tf.Variable 'beta2_power:0' shape=() dtype=float32_ref>
<tf.Variable 'W/Adam:0' shape=(10, 20) dtype=float64_ref>
<tf.Variable 'W/Adam_1:0' shape=(10, 20) dtype=float64_ref>

还会创建2个Adam节点