Guest User

Untitled

a guest
Apr 19th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. def add_evaluation_step(result_tensor, ground_truth_tensor):
  2.  
  3. with tf.name_scope('accuracy'):
  4. with tf.name_scope('correct_prediction'):
  5. prediction = tf.argmax(result_tensor, 1)
  6. correct_prediction = tf.equal(
  7. prediction, tf.argmax(ground_truth_tensor, 1))
  8. with tf.name_scope('accuracy'):
  9. evaluation_step = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  10. tf.summary.scalar('accuracy', evaluation_step)
  11. print('prediction shape :: {}'.format(ground_truth_tensor))
  12.  
  13. #Add confusion matrix
  14. batch_confusion = tf.confusion_matrix(tf.argmax(ground_truth_tensor, 1), prediction,
  15. num_classes=7,
  16. name='batch_confusion')
  17. # Create an accumulator variable to hold the counts
  18. confusion = tf.Variable( tf.zeros([7,7],
  19. dtype=tf.int32 ),
  20. name='confusion' )
  21. # Create the update op for doing a "+=" accumulation on the batch
  22. confusion_update = confusion.assign( confusion + batch_confusion )
  23. # Cast counts to float so tf.summary.image renormalizes to [0,255]
  24. confusion_image = tf.reshape( tf.cast( confusion_update, tf.float32),
  25. [1, 7, 7, 1])
  26.  
  27. tf.summary.image('confusion',confusion_image)
  28.  
  29. return evaluation_step, prediction
Add Comment
Please, Sign In to add comment