Hi Ich lerne Tensorflow. Dies ist mein Code, ein einfaches mehrdimensionales Tensorflow-Beispiel. Laufende Umgebung ist Python3.5.3, Tensorflow 0.12.1, Windows7.Warum steigt das Trainingsergebnis meines Tensorflow-Beispielcodes?
import tensorflow as tf
# Input data & output data
x1_data = [1.0, 0.0, 3.0, 0.0, 5.0]
x2_data = [0.0, 2.0, 0.0, 4.0, 5.0]
y_data = [1.0, 2.0, 3.0, 4.0, 5.0]
# W1, W2, b random generation
# W1 = 1, W2 = 1, b = 0 is ideal
W1 = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
W2 = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
# Our hypothesis
hypothesis = W1 * x1_data + W2 * x2_data + b
# Simplified cost function
cost = tf.reduce_mean(tf.square(hypothesis - y_data))
# Minimize
a = tf.Variable(0.1) # Learning Rate
optimizer = tf.train.GradientDescentOptimizer(a)
train = optimizer.minimize(cost)
# Initialise
init = tf.global_variables_initializer()
# Launch
sess = tf.Session()
sess.run(init)
# Train loop
for step in range(10):
sess.run(train)
print(step, sess.run(cost), sess.run(W1), sess.run(W2), sess.run(b))
Ich erwartete, dass das Ergebnis als Trainings-Loops abnehmen wird.
aber es erhöht sich unendlich.
Derselbe Code auf einer Variablen hat gut funktioniert und abgenommen.
Ich weiß nicht, warum 2-Variable erhöht ...
0 52.0504 [ 1.47101164] [ 2.24049234] [ 0.86718893]
1 157.129 [-1.74108529] [-1.84496927] [-0.22162986]
2 478.055 [ 4.02118969] [ 5.11457825] [ 1.86127353]
3 1457.33 [-5.99311352] [-7.13181305] [-1.60902405]
4 4445.18 [ 11.50830746] [ 14.20653534] [ 4.60829926]
5 13561.2 [-19.06884766] [-23.10119247] [-6.10722733]
6 41374.3 [ 34.32733154] [ 42.03698349] [ 12.74352837]
7 126232.0 [-58.95558929] [-71.76408386] [-20.05929375]
8 385134.0 [ 103.96767426] [ 126.9929657] [ 37.3527832]
9 1.17505e+06 [-180.62704468] [-220.19728088] [-62.82305145]