Source code for unet.metrics

import tensorflow as tf


[docs]def mean_iou(y_true, y_pred): y_true = tf.cast(y_true, tf.dtypes.float64) y_pred = tf.cast(y_pred, tf.dtypes.float64) I = tf.reduce_sum(y_pred * y_true, axis=(1, 2)) U = tf.reduce_sum(y_pred + y_true, axis=(1, 2)) - I return tf.reduce_mean(I / U)
[docs]def dice_coefficient(y_true, y_pred, smooth=1): intersection = tf.reduce_sum(y_true * y_pred, axis=[1, 2, 3]) union = tf.reduce_sum(y_true, axis=[1, 2, 3]) + tf.reduce_sum(y_pred, axis=[1, 2, 3]) dice = tf.reduce_mean((2. * intersection + smooth) / (union + smooth), axis=0) return dice