不兼容的形状:[14250,10]与[15000,10]

时间:2018-09-22 07:07:46

标签: python tensorflow jupyter-notebook incompatibletypeerror

我是tensorflow的新手,并且正在执行udacity程序。我被要求在notMNIST数据集上构建图像分类器。

我附上了代码和错误,请尽一切可能帮助我。谢谢。

features_count = 784
labels_count = 10

features = tf.placeholder(tf.float32)
labels = tf.placeholder(tf.float32)

weights = tf.Variable(tf.truncated_normal((features_count, 
labels_count)))
biases = tf.Variable(tf.zeros(labels_count))

train_feed_dict = {features: train_features,labels: train_labels}
valid_feed_dict = {features: valid_features, labels: valid_labels}
test_feed_dict = {features: test_features, labels: test_labels}

# Linear function Wx+b
logits = tf.add(tf.matmul(features,weights), biases)

prediction = tf.nn.softmax(logits)

#Cross entropy
cross_entropy = -tf.reduce_sum(labels * tf.log(prediction), 
reduction_indices = 1)

# Training loss
loss = tf.reduce_mean(cross_entropy)

# Initialize all the variables
init = tf.global_variables_initializer()

with tf.Session() as sess:
  sess.run(init)
  sess.run(loss, feed_dict = train_feed_dict)
  sess.run(loss, feed_dict = valid_feed_dict)
  sess.run(loss, feed_dict = test_feed_dict)
  biases_data = sess.run(biases)

这是我得到的错误:

InvalidArgumentError: Incompatible shapes: [14250,10] vs. [15000,10]
 [[Node: mul_7 = Mul[T=DT_FLOAT, 
_device="/job:localhost/replica:0/task:0/device:CPU:0"] . 
(_arg_Placeholder_16_0_1, Log_7)]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call 
last)
<ipython-input-46-83a463c8a201> in <module>()
 53 with tf.Session() as sess:
 54     sess.run(init)
 ---> 55     sess.run(loss, feed_dict = train_feed_dict)
 56     sess.run(loss, feed_dict = valid_feed_dict)
 57     sess.run(loss, feed_dict = test_feed_dict)

0 个答案:

没有答案