TensorFlow文档入门

TensorFlow文档入门,tensorflow,Tensorflow,我不确定这是否是提出这个问题的正确地点。我正在跟踪,并遇到了以下示例代码: W = tf.Variable([.3], tf.float32) b = tf.Variable([-.3], tf.float32) x = tf.placeholder(tf.float32) linear_model = W * x + b In the section on loss function it has the following: y = tf.placeholder(tf.float

我不确定这是否是提出这个问题的正确地点。我正在跟踪,并遇到了以下示例代码:

W = tf.Variable([.3], tf.float32)

b = tf.Variable([-.3], tf.float32)

x = tf.placeholder(tf.float32)

linear_model = W * x + b


In the section on loss function it has the following:

y = tf.placeholder(tf.float32)

squared_deltas = tf.square(linear_model - y)

loss = tf.reduce_sum(squared_deltas)

print(sess.run(loss, {x:[1,2,3,4], y:[0,-1,-2,-3]}))
为什么
y[0,-1,-2,-3]的值是
?基于

linear_model = W * x + b, 
y为0.3x-0.3。所以对于[1,2,3,4]的x,y应该是[0,0.3,0.6,0.9]。
还是我遗漏了什么?

是的,你遗漏了什么。本练习的目标是显示您首先构建一个图(W*x+b=y),然后为占位符提供变量。 为此,您需要提供x和y,并查看您期望的wat(y变量)和您得到的wat(线性_模型变量)之间的差异

你混淆了方程的结果和教程想要从方程中得到的结果。如果你继续学习教程,他们可能会学习你如何训练你的体重,以获得你期望的解决方案


祝你好运

在这个代码片段中,“x”是输入,“y”用于标签的目的,正如您似乎已经理解的那样

“W”和“b”是程序应该“学习”的变量,当x=[1,2,3,4]时,y最终为[0,-1,-2,-3]

您看到的“W”和“b”的值是初始值。
这段代码中不包括更新步骤,您将在基于损失函数计算梯度后更新权重。在几次迭代之后,你应该得到你的“W”和“b”,这样当x=[1,2,3,4]时,你会得到y=[0,-1,-2,-3]

,还有澄清的会议