[bc8010]: / SegNet / SegNetCMR / evaluation.py

Download this file

21 lines (16 with data), 788 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import tensorflow as tf
def loss_calc(logits, labels):
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels)
loss = tf.reduce_mean(cross_entropy)
tf.summary.scalar('loss', loss)
return loss
def evaluation(logits, labels):
correct_prediction = tf.equal(tf.argmax(logits, 3) > 0, labels > 0)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
tf.summary.scalar('accuracy', accuracy)
return accuracy
def IoU_calc(logits, labels):
inter = tf.reduce_sum(tf.cast((tf.argmax(logits, 3) > 0) & (labels > 0), tf.float32), [1, 2])
union = tf.reduce_sum(tf.cast((tf.argmax(logits, 3) > 0) | (labels > 0), tf.float32), [1, 2])
IoU = tf.reduce_mean(tf.cast(inter/union, tf.float32))
return IoU