def dice_core_mask(mask):
def dice_core_closure(y_true, y_pred):
"""
Computes the Sorensen-Dice metric, where P come from class 1,2,3,4,5
TP
Dice = 2 -------
T + P
Parameters
----------
y_true : keras.placeholder
Placeholder that contains the ground truth labels of the classes
y_pred : keras.placeholder
Placeholder that contains the class prediction
Returns
-------
scalar
Dice metric
"""
y_pred_decision = K.cast(y_pred / K.max(y_pred, axis=1, keepdims=True), 'int8')
mask_true = K.sum(y_true[:, [1, 3, 4], :, :, :], axis=1)
mask_pred = K.sum(y_pred_decision[:, [1, 3, 4], :, :, :], axis=1)
y_sum = K.sum(mask * mask_true * mask_pred)
return (2. * y_sum + K.epsilon()) / (K.sum(mask * mask_true) + K.sum(mask * mask_pred) + K.epsilon())
return dice_core_closure
评论列表
文章目录