Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_evaluation_step(result_tensor, ground_truth_tensor):
- with tf.name_scope('accuracy'):
- with tf.name_scope('correct_prediction'):
- prediction = tf.argmax(result_tensor, 1)
- correct_prediction = tf.equal(
- prediction, tf.argmax(ground_truth_tensor, 1))
- with tf.name_scope('accuracy'):
- evaluation_step = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
- tf.summary.scalar('accuracy', evaluation_step)
- print('prediction shape :: {}'.format(ground_truth_tensor))
- #Add confusion matrix
- batch_confusion = tf.confusion_matrix(tf.argmax(ground_truth_tensor, 1), prediction,
- num_classes=7,
- name='batch_confusion')
- # Create an accumulator variable to hold the counts
- confusion = tf.Variable( tf.zeros([7,7],
- dtype=tf.int32 ),
- name='confusion' )
- # Create the update op for doing a "+=" accumulation on the batch
- confusion_update = confusion.assign( confusion + batch_confusion )
- # Cast counts to float so tf.summary.image renormalizes to [0,255]
- confusion_image = tf.reshape( tf.cast( confusion_update, tf.float32),
- [1, 7, 7, 1])
- tf.summary.image('confusion',confusion_image)
- return evaluation_step, prediction
Add Comment
Please, Sign In to add comment