ValueError:无法为Tensor' Placeholder_1:0'提供形状值(100,1),它具有形状'(?,10)'

时间:2018-01-14 14:23:00

标签: python-3.x tensorflow machine-learning deep-learning mnist

我正在从Tensorflow文档中学习Tensorflow,并且正在尝试实施MNIST,但我一直收到此错误。

# placeholders for the data
x = tf.placeholder(tf.float32, [None, 784])
y = tf.placeholder(tf.float32, [None, 10])

# weights and biases
w = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

# softmax model
activation = tf.nn.softmax_cross_entropy_with_logits(logits = tf.matmul(x, w) + b, labels=y)
# backpropagation
train = tf.train.GradientDescentOptimizer(0.5).minimize(activation)

# creating tensorflow session
s = tf.InteractiveSession()

# i have already initialised the variables

# gradient descent
for i in range(100):
    x_bat, y_bat= create_batch(x_train, y_train, size=100)
    train_step = s.run(train, feed_dict={x: x_bat, y: y_bat})

这是代码

Conflicting parameter types in implementation of 'userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:': 'void (^ _Nonnull __strong)(void)' vs 'void (^__strong _Nonnull)()'

1 个答案:

答案 0 :(得分:0)

问题在于create_batch函数输出错误的y_bat形状。最有可能的是,你忘了做一个热门编码。

即,当前y_bat是整数0..9的[100]向量,但它应该是0 {1}的[100, 10]向量。

如果您使用input_data.read_data_sets函数获取数据,则只需添加one_hot=True