Def neh
Def neh

Reputation: 19

problem with brain tumor segmentation 2D Unet with Dice_coef_loss

Knowing that I am training using the 4 MRI modalities, when I use categorical cross-entropy, in this tutorial from brain_tumor_segmentation_u_net the IOU and Dice coefficients work fine. However, when I switch to Dice_coef_loss or other loss functions, the loss doesn't change and showed same metrics in all epochs.

import keras
import keras.backend as K
# dice loss as defined above for 4 classes
def dice_coef(y_true, y_pred, smooth=1e-6):
    class_num = 4
    for i in range(class_num):
        y_true_f = K.flatten(y_true[:,:,:,i])
        y_pred_f = K.flatten(y_pred[:,:,:,i])
        intersection = K.sum(y_true_f * y_pred_f)
        loss = ((2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth))
        if i == 0:
            total_loss = loss
        else:
            total_loss = total_loss + loss
    total_loss = total_loss / class_num
    return total_loss

def dice_coef_loss(y_true, y_pred):
    return 1-dice_coef(y_true, y_pred)

I tried solutions from : solution1 and solution2 but nothing changed. Could you please help me figure out why?

When I print the values min and max values og a patch and y_pred, I get the following: y_batch min/max: 0.0 / 1.0 Model output (y_pred) min/max: 0.08728714 / 0.43650725 Could this discrepancy be the cause of the issue? Thank you so much for your help

Upvotes: 1

Views: 20

Answers (0)

Related Questions