Reputation: 1626
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
_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]}))
Upvotes: 0
Views: 392
Reputation: 19634
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. If it consist of the probability vectors (that is, softmax
was already applied) then you can get the accuracy as follows:
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.
If _pre
consists of the logits vectors (that is, if applying softmax
on _pre
will give the probability vectors),
then this will do the job:
acc=tf.reduce_max(tf.nn.softmax(_pre), 1)
print(acc.eval(feed_dict={_x: [i]}))
Upvotes: 2