0
votes

I am using Tensor Flow's retraining example on my own dataset. The final test evaluation outputs the final test accuracy and the names of the misclassified images:

test_accuracy, predictions = eval_session.run(
  [evaluation_step, prediction],
  feed_dict={
      bottleneck_input: test_bottlenecks,
      ground_truth_input: test_ground_truth
  })
  tf.logging.info('Final test accuracy = %.1f%% (N=%d)' %
              (test_accuracy * 100, len(test_bottlenecks)))

  if FLAGS.print_misclassified_test_images:
    tf.logging.info('=== MISCLASSIFIED TEST IMAGES ===')
    for i, test_filename in enumerate(test_filenames):
      if predictions[i] != test_ground_truth[i]:
        tf.logging.info('%70s  %s' % (test_filename, list(image_lists.keys())[predictions[i]]))

How can I also print the probabilities associated to the predictions for all classes?

For example:

image1 - A: 0.5; B: 0.3; C: 0.1; D: 0.1

image2 - A: 0.3; B: 0.2; C: 0:4; D: 0.1

1

1 Answers

0
votes

I think I found the answer myself.

The probabilities can be obtained like this:

probs = tf.nn.softmax(final_tensor)
probabilities = sess.run(probs, feed_dict={bottleneck_input: test_bottlenecks,
    ground_truth_input: test_ground_truth})

Then, they can be accessed like this:

for i, test_filename in enumerate(test_filenames):        
    tf.logging.info('%70s  %f %f %f %f' %
                      (test_filename,
                       probabilities[i][0], probabilities[i][1], probabilities[i][2], probabilities[i][3]))