2017-01-02 6 views
3

Tensorflowと機械学習の新機能です。バッチ処理された入力を模倣するために基本的なTensorflow exampleを修正しようとしましたが、収束させることができませんでした。テンソルフローがnx1整数入力(カラムベクトル)で収束しない

x_dataを[0,1]の範囲内に変更すると、正しくWを計算することができます。

x_data = np.random.rand(numelements,1).astype(np.float32) 

私のコードに何か問題がありますか?ここにコピーがあります:

import tensorflow as tf 
import numpy as np 

# number of training samples 
numelements = 100 

# define input, and labled values 
# note the inptu and output are actually scalar value 
#x_data = np.random.rand(numelements,1).astype(np.float32) 
x_data = np.random.randint(0, 10, size=(numelements,1)).astype(np.float32) 
y_data = x_data * 10 

# Try to find values for W and b that compute y_data = W * x + b 
x = tf.placeholder(tf.float32, [None, 1]) 
W = tf.Variable(tf.zeros([1])) 
b = tf.Variable(tf.zeros([1])) 
y = tf.mul(x, W) + b 

# Minimize the mean squared errors. 
loss = tf.reduce_mean(tf.square(y - y_data)) 
optimizer = tf.train.GradientDescentOptimizer(0.5) 
train = optimizer.minimize(loss) 

# Before starting, initialize the variables. We will 'run' this first. 
init = tf.global_variables_initializer() 

# Launch the graph. 
sess = tf.Session() 
sess.run(init) 

# Fit the line. 
for step in range(81): 
sess.run(train, feed_dict={x: x_data}) 
if step % 20 == 0: 
    print(step, sess.run(W), sess.run(b)) 

答えて

0

私の友人は私のグラデーションデサントの練習率が高すぎるとわかりました。このpostのヒントを使用すると、損失が大きくなり、最終的にあふれ始めることがはっきりと分かります。

学習率を0.005に変更し、収束を開始しました。

関連する問題