Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation metrics #894

Closed
emi-dm opened this issue Sep 15, 2023 · 3 comments
Closed

Segmentation metrics #894

emi-dm opened this issue Sep 15, 2023 · 3 comments

Comments

@emi-dm
Copy link

emi-dm commented Sep 15, 2023

Would it be possible to include default metrics in Keras for image segmentation? E.x Dice, IoU, HD, etc.

@emi-dm
Copy link
Author

emi-dm commented Sep 15, 2023

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!

@soumik12345
Copy link
Contributor

@emi-research-dl This is probably better suited for KerasCV

@emi-dm
Copy link
Author

emi-dm commented Sep 17, 2023

@soumik12345 Totally agree!!

@emi-dm emi-dm closed this as completed Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants