ValueError: Dimensions must be equal, but are 784 and 10 for 'add' (op: 'Add') with input shapes: [7

ValueError: Dimensions must be equal, but are 784 and 10 for 'add' (op: 'Add') with input shapes: [784,784], [10].

出现这种错误是由于矩阵位置放错了

ValueError: Dimensions must be equal, but are 784 and 10 for 'add' (op: 'Add') with input shapes: [7_第1张图片

#定义两个placeholder
x = tf.placeholder(tf.float32, [None, 784])
y = tf.placeholder(tf.float32, [None, 10])

#神经网络层
weight = tf.Variable(tf.zeros([784, 10]))
bias = tf.Variable(tf.zeros([10]))
predict = tf.matmul(weight, x) + bias


此时需要将predict = tf.matmul(weight, x) + bias改成

predict = tf.matmul(x, weight) + bias

你可能感兴趣的:(机器学习,bug原因及解决)