【问题标题】:Tensorflow not converging with nx1 integer input (column vector)Tensorflow 不与 nx1 整数输入(列向量)收敛
【发布时间】:2017-01-02 19:44:47
【问题描述】:

我是 TensorFlow 和机器学习的新手。我尝试修改基本的Tensorflow example 以模拟批量输入,但无法使其收敛。

如果我将 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))

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    我的朋友帮我弄清楚我的梯度下降训练率太高了。使用post 中的提示,我可以清楚地看到损失越来越大,最终开始溢出。

    我将学习率更改为 0.005,它开始收敛。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 2016-01-19
      相关资源
      最近更新 更多