tensorflow Value error,求助
发布于 1月前 作者 Kalman 来自问答

X_data = np.random.rand(100).astype(np.float32)
Y_data = X_data*0.1 + 0.3
plt.plot(X_data, Y_data)
plt.show()
Weights = tf.Variable(tf.random.uniform([1], -1.0, 1.0))
biases = tf.Variable(tf.zeros([1]))
y = Weights*X_data + biases

loss = tf.reduce_mean(tf.square(y-Y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
init = tf.initializer_all_variables

sess = tf.Session()
sess.run(init)

for step in range(201):
sess.run(train)
if step%20 == 0:
print(step,sess.run(Weights),sess.run(biases))


一个tensorflow的回归算法,运行时报错,错误如下:


提示是类型错误,numpy to tensor,后来我换成tensor类型,结果还是Value error,


求助求助

回到顶部