我需要某人的幫助才能向我解釋下面的代碼。我有點新TensorFlow,但我在下面TensorFlow代碼幫助 - 入門示例
import tensorflow as tf
# Model parameters
#Why are variables initialize with .3 and -.3
W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
中的代碼中定義的特定問題,什麼是X,B,W和Y變量代表什麼?
# Model input and output
x = tf.placeholder(tf.float32) # this is the input
linear_model = W * x + b # this is the linear_model operation
y = tf.placeholder(tf.float32) # Is this the output we're trying to predict.
爲什麼代碼將參數值0.01傳遞給GradientDescentOptimizer函數?
# loss - measure how far apart the current model is from the provided data.
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01) # Why are we passing the value '0.01'
train = optimizer.minimize(loss)
y_train在這裏代表什麼?
# training data
x_train = [1, 2, 3, 4] # the input variables we know
y_train = [0, -1, -2, -3] #
# training loop
init = tf.global_variables_initializer() # init is a handle to the TensorFlow sub-graph that initializes all the global variables. Until we call sess.run, the variables are unitialized
sess = tf.Session() # Sesson encapsulates the control and state of the TensorFlow runtime. ITs used to evaluate the nodes, we must run the computational graph within a session
sess.run(init) # reset values to wrong
for i in range(1000):
sess.run(train, {x: x_train, y: y_train})
這裏的變量curr_W,curr_b代表什麼?
# evaluate training accuracy
# Why does the variables W and b represent?
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x: x_train, y: y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))
的代碼示例來自Tensorflow網站:https://www.tensorflow.org/get_started/get_started#complete_program
我的代碼示例中的偏見和重量的值是多少? –
'W'和'b'的初始值分別爲0.3和-0.3,正如答案中所述,這並不重要。然後,在訓練期間,這些值不斷變化(一個很好的練習 - 在每次迭代中打印出來),直到最後,它們接近-1和1。 – Maxim