Improvement of GDL in case of void label - Correction of weighting
@@ -92,16 +92,18 @@ def generalised_dice_loss(prediction,
weight_map_nclasses = tf.reshape(
tf.tile(weight_map, [n_classes]), prediction.get_shape())
ref_vol = tf.sparse_reduce_sum(
- weight_map_nclasses * one_hot, reduction_axes=[0]) + 0.1
+ weight_map_nclasses * one_hot, reduction_axes=[0])
+
intersect = tf.sparse_reduce_sum(
weight_map_nclasses * one_hot * prediction, reduction_axes=[0])
seg_vol = tf.reduce_sum(
- tf.multiply(weight_map_nclasses, prediction), 0) + 0.1
+ tf.multiply(weight_map_nclasses, prediction), 0)
else:
- ref_vol = tf.sparse_reduce_sum(one_hot, reduction_axes=[0]) + 0.1
+ ref_vol = tf.sparse_reduce_sum(one_hot, reduction_axes=[0])
+
intersect = tf.sparse_reduce_sum(one_hot * prediction,
reduction_axes=[0])
- seg_vol = tf.reduce_sum(prediction, 0) + 0.1
+ seg_vol = tf.reduce_sum(prediction, 0)
if type_weight == 'Square':
weights = tf.reciprocal(tf.square(ref_vol))
elif type_weight == 'Simple':
@@ -111,7 +113,9 @@ def generalised_dice_loss(prediction,
else:
raise ValueError("The variable type_weight \"{}\"" \
"is not defined.".format(type_weight))
-
+ new_weights = tf.where(tf.is_inf(weights), tf.zeros_like(weights), weights)
+ weights = tf.where(tf.is_inf(weights), tf.ones_like(weights) *
+ tf.reduce_max(new_weights), weights)
generalised_dice_numerator = \
2 * tf.reduce_sum(tf.multiply(weights, intersect))
generalised_dice_denominator = \
