gpt4 book ai didi

Tensorflow 错误 : Minimum tensor rank: 1 but got: 1

转载 作者:行者123 更新时间:2023-12-03 17:18:29 25 4
gpt4 key购买 nike

我在尝试评估我的模型时遇到以下错误。

tensorflow.python.framework.errors.InvalidArgumentError: Minimum tensor rank: 1 but got: 1 [[Node: ArgMax_1 = ArgMax[T=DT_INT64, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_Placeholder_1_0, ArgMax_1/dimension/_40)]]

这是相关的代码

        # Predictions for the current training minibatch.
train_prediction = tf.nn.softmax(logits)
correct_prediction = tf.equal(tf.argmax(train_prediction, 1), tf.argmax(train_labels, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

sess.run(tf.initialize_all_variables())
for i in range(1000000):
start_time = time()

images, labels = get_batch(fifo_queue, FLAGS.batch_size)

feed_dict = {
train_images: images,
train_labels: labels
}

_, loss_value, learn_rate, predictions = sess.run(
[train_step, cross_entropy, learning_rate, train_prediction],
feed_dict=feed_dict)

duration = time() - start_time
if i % 1 == 0:
# Print status to stdout.
print('Step %d: loss = %.3f (%.3f sec)' % (i, loss_value, duration))

train_accuracy = accuracy.eval(feed_dict={
train_images: images, train_labels: labels, keep_prob: 1.0})
print("step %d, training accuracy %g"%(i, train_accuracy))
train_step.run(feed_dict={train_images: images[0], train_labels: labels[1], keep_prob: 0.5})

`

我还没有尝试太多,因为我刚刚开始我的第一个模型评估,这个错误(表示期待 1 并得到 1)并没有太大帮助。

最佳答案

错误信息不是很好,但查看 the code可能会解释发生了什么。

出现问题是因为 train_labels是(大概)一个一维向量。维度从 0 开始编号,因此向量只有第 0 个维度,但是您对 tf.argmax(train_labels, 1) 的调用尝试在不存在的第一维中获取 argmax。

事实上,根本不需要采用标签的 argmax。相反,您可以简单地编写:

correct_prediction = tf.equal(tf.argmax(train_prediction, 1), train_labels)

关于Tensorflow 错误 : Minimum tensor rank: 1 but got: 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37621639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com