在TensorFlow中评估MNIST测试数据期间如何从每个输出节点获取值? [英] How to get the value from each output-node during eval MNIST testdata in TensorFlow?

查看:299
本文介绍了在TensorFlow中评估MNIST测试数据期间如何从每个输出节点获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用TensorFlow训练卷积神经网络(CNN).训练结束后,我将使用以下代码计算准确性:

I train a convolutional neural network (CNN) with TensorFlow. When the training is finished I calculate the accuracy with the following code:

...
correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))
eval_batch_size = 1
good = 0
total = 0
for i in range(int(mnist.test.num_examples/eval_batch_size)):
    testSet = mnist.test.next_batch(eval_batch_size, shuffle=False)
    good += accuracy.eval(feed_dict={ x: testSet[0], y: testSet[1]})
    total += testSet[0].shape[0]
accuracy_eval = good/total

对于好",当正确检测到测试图像时,我得到的值为1.0,否则为0.0.

For "good" I get the value 1.0 when the test image is correct detected and the value 0.0 if not.

我想获取所有十个输出节点的值.例如,我用手写"8"评估测试图像,因此数字"8"的输出节点可能是0.6,数字"3"的输出节点是0.3,"5"的输出节点是0.05,最后一个0.05超过其他七个输出节点.

I want get the values for all ten output-nodes. For example, I evaluate a test-image with a handwritten "8" so maybe the output-node for the number "8" is 0.6 and for the number "3" is 0.3 and for "5" is 0.05 and the last 0.05 spread out over the seven other output-nodes.

那么我如何在TensorFlow中为每个测试图像获取所有这十个值?

So how I get all this ten values for each test image in TensorFlow?

推荐答案

您可以通过添加以下行来做到这一点:

You can do that by adding the following line:

pred=prediction.eval(feed_dict={ x: testSet[0], y: testSet[1]})

紧接着

testSet = mnist.test.next_batch(eval_batch_size, shuffle=False)

然后pred将是一个包含1个概率向量的数组,这是您感兴趣的向量.

Then pred will be an array that contains 1 probability vector, and this is the vector you are interested in.

这篇关于在TensorFlow中评估MNIST测试数据期间如何从每个输出节点获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆