【发布时间】:2017-05-06 01:15:52
【问题描述】:
我正在使用 tensorflow 来训练和使用一个小型神经网络(具有两个类的 2d 分类),但是我遇到了一个非常奇怪的问题并且看不到我做错了什么: 当我只为精度评估为 1 的测试批次绘制 the predictions vs the true labels 时,我显然有一些错误分类的样本。在我看来,tf.argmax 负责错误地评估为 1 的准确性,但显然这不是真正的原因。 无论如何,我通过计算最后一层输出的准确率得出了这个结论:
with tf.name_scope('accuracy'):
plabel = tf.argmax(y, 1) # vector of predicted label, elem {0,1}^batch_size
tlabel = tf.argmax(y_, 1) # similar vector of true labels
correct_predictions = tf.cast(tf.equal(plabel, tlabel), tf.float32)
...
with tf.Session() as sess:
batchx, batchy = generate_batch()
predictions, acc = sess.run([y, accuracy], feed_dict={x: batchx, y_: batchy})
mistakes = 0.
for j in range(batch_size):
if (predictions[j, 0] - predictions[j, 1])*(batchy[j, 0] - batchy[j, 1]) < 0:
print("mistake: ", predictions[j], batchy[j])
mistakes += 1./batch_size
print("Acc = {} / {} = 1-m/b".format(acc, 1. - mistakes))
x 和 y_ 是输入张量,y 是最后一层,模型已经训练完毕。
它给了我以下输出:
Acc = 1.0 / 0.86 = 1-m/b
这些值应该相同。
该图还表明真实准确度不是 1,或者评估的准确度张量与预测 (y) 不属于同一运行。
我没有发现任何暗示 tf.argmax 确实是问题所在,我非常绝望。所以提前感谢您的帮助
【问题讨论】:
标签: tensorflow