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