ValueError: setting an array element with a sequence.????
在只使用Tensorflow内置库的情况下,完成线性回归,结果出现ValueError: setting an array element with a sequence错误。之前找的相关回答,都是有其它库介入的情况的错误,比如numpy。而我现在遇到的错误Queue一直不能修正。这个技术难度应该不大,但是我一直没能找到合适解决办法,希望大家可以帮忙看一下!
import tensorflow as tf
x_data = tf.Variable(tf.random_normal([2000, 3])) # random test data
noise = tf.Variable(tf.random_normal([2000, 1])) # random noise
w_real = tf.constant([[3.0, 5.1, 1.7]]) # weight
b_real = tf.constant(-0.2) # bias
y_data = tf.Variable(tf.matmul(x_data, tf.transpose(w_real)) + b_real + noise)
NUM_STEPS = 10
x = tf.placeholder(dtype=tf.float32, shape=[None, 3], name="x_train")
y_true = tf.placeholder(dtype=tf.float32, shape=None, name="y_true")
with tf.name_scope("inference") as scope:
w = tf.Variable(tf.zeros([3, 1]))
b = tf.Variable(0.0)
y_pred = tf.matmul(x, w) + b
with tf.name_scope("loss") as scope:
loss = tf.reduce_mean(1 / 2 * tf.square(y_pred - y_true))
with tf.name_scope("train") as scope:
learning_rate = 0.1
optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for step in range(NUM_STEPS):
sess.run(train, feed_dict={x: x_data, y_true: y_data})
print(step, sess.run([w, b]))
tf.summary.FileWriter("./graph", sess.graph)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tensorflow的输入必须array必须是n*n(2*2或者3*3),即行和列数必须一致。