Tensorflow GradientDescentOptimizer - 它如何连接到 tf.Variables?
Tensorflow GradientDescentOptimizer - how does it connect to tf.Variables?
我很好奇你如何告诉它最小化哪些变量。例如,在此线性回归代码中,TF 可以很好地优化 weights/bias 而无需告知变量名称:
y = W * x + b
cost_func = tf.nn.l2_loss(y_ - y) # squared error
trainer = tf.train.GradientDescentOptimizer(0.01).minimize(cost_func)
tensorflow 怎么知道我要它更新 W
和 b
?它是否只看到这些是会话中唯一的变量?
它取自 tf.trainable_variables()
,其中包括使用 trainable=True
标志(默认)
创建的所有变量
我很好奇你如何告诉它最小化哪些变量。例如,在此线性回归代码中,TF 可以很好地优化 weights/bias 而无需告知变量名称:
y = W * x + b
cost_func = tf.nn.l2_loss(y_ - y) # squared error
trainer = tf.train.GradientDescentOptimizer(0.01).minimize(cost_func)
tensorflow 怎么知道我要它更新 W
和 b
?它是否只看到这些是会话中唯一的变量?
它取自 tf.trainable_variables()
,其中包括使用 trainable=True
标志(默认)