daifeng2016 / End-to-end-CD-for-VHR-satellite-image

The project aims to contribute to geoscience community
65 stars 22 forks source link

question on weighted_bce loss #12

Open songkq opened 4 years ago

songkq commented 4 years ago

Hey, As for the tensors y_true and y_pred with a shape of [1, 256, 256, 1],
the class_loglossesis a tensor with a shape of [1] so that class_weights here cannot do anythingwhen executing the following line weighted_bce = K.sum(class_loglosses * K.constant(class_weights))

def weighted_bce_dice_loss(y_true,y_pred):
    class_loglosses = K.mean(K.binary_crossentropy(y_true, y_pred), axis=[0, 1, 2])
    class_weights = [0.1, 0.9]
    weighted_bce = K.sum(class_loglosses * K.constant(class_weights))
    return weighted_bce + 0.5 * (dice_coef_loss(y_true, y_pred))

I wonder if there's a confusion for the weighted loss? Or it can be replaced with the K.weighted_binary_crossentropy within pos_weight for the positive samples? Any advice?