Closed emi-dm closed 10 months ago
I tried this:
from keras_core import backend as K
def jaccard_distance_loss(y_true, y_pred, smooth=100):
intersection = K.sum(K.sum(K.abs(y_true * y_pred), axis=-1))
sum_ = K.sum(K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1))
jac = (intersection + smooth) / (sum_ - intersection + smooth)
return (1 - jac) * smooth
def dice_metric(y_pred, y_true):
intersection = K.sum(K.sum(K.abs(y_true * y_pred), axis=-1))
union = K.sum(K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1))
return 2*intersection / union
size = 10
y_true = np.zeros(shape=(size,size))
y_true[3:6,3:6] = 1
y_pred = np.zeros(shape=(size,size))
y_pred[3:5,3:5] = 1
loss = jaccard_distance_loss(y_true,y_pred)
metric = dice_metric(y_pred,y_true)
print(f"loss: {loss}")
print(f"dice_metric: {metric}")
It seems that keras_core does not yet have backend support. Can someone help me?
Thanks in advanced!
@emi-research-dl This is probably better suited for KerasCV
@soumik12345 Totally agree!!
Would it be possible to include default metrics in Keras for image segmentation? E.x Dice, IoU, HD, etc.