I am trying to write my own loss function for the UNET. In this function I want to assign the all differences bigger than 10 between y_true
and y_pred
to 10 and all differences smaller than 1 to 1. is there any convenient way of comparing and assigning to tensors?
def weighted_cross_entropyy(i):
def loss(y_true, y_pred):
diff = K.abs(y_true - y_pred)
diff[K.less(diff, 1)] == 1
diff[K.greater(diff, 10)] == 10
return K.mean(K.square((y_pred - y_true)* diff), axis= -1)
return loss