[英]Tensorflow MNIST - accuracy of particular test image
Here is the code that I used for predicting particular mnist image, how can i get accuracy by which the prediction is done ? 这是我用于预测特定图像的代码,如何获得进行预测的准确性?
_pre are logits _pre是登录
_x = loaded_graph.get_tensor_by_name('x:0')
_y = loaded_graph.get_tensor_by_name('y:0')
_pre = loaded_graph.get_tensor_by_name('prediction:0')
p = tf.argmax(_pre, 1)
i = imageprepare('./image.png')
print(p.eval(feed_dict={_x: [i]}))
I am assuming that "accuracy" means "the probability that was assigned to the selected label". 我假设“准确性”是指“分配给所选标签的概率”。 From your code it is unclear how
_pre
was created. 从您的代码尚不清楚
_pre
是如何创建的。 If it consist of the probability vectors (that is, softmax
was already applied) then you can get the accuracy as follows: 如果它由概率向量组成(即,已经应用
softmax
),则可以按如下所示获得准确性:
acc=tf.reduce_max(_pre, 1)
print(acc.eval(feed_dict={_x: [i]}))
The reason is that p
was the location of the maximal probability, while the accuracy ( acc
in this case) is the maximal probability itself. 原因是
p
是最大概率的位置,而准确性(在这种情况下为acc
)是最大概率本身。
If _pre
consists of the logits vectors (that is, if applying softmax
on _pre
will give the probability vectors), 如果
_pre
由logits向量(即,如果施加softmax
上_pre
将给概率载体),
then this will do the job: 然后这将完成工作:
acc=tf.reduce_max(tf.nn.softmax(_pre), 1)
print(acc.eval(feed_dict={_x: [i]}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.