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

Dice loss implementation #85

Open
mrgloom opened this issue Dec 13, 2018 · 2 comments
Open

Dice loss implementation #85

mrgloom opened this issue Dec 13, 2018 · 2 comments

Comments

@mrgloom
Copy link

mrgloom commented Dec 13, 2018

I wonder why in dice loss implementation union is just sum and not sum - intersection, i.e. in case of sum seems mask itersection area is calculated twice?

https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py#L27
https://github.com/keras-team/keras-contrib/blob/master/keras_contrib/losses/jaccard.py#L33

@jizhang02
Copy link

I wonder why in dice loss implementation union is just sum and not sum - intersection, i.e. in case of sum seems mask itersection area is calculated twice?

https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py#L27
https://github.com/keras-team/keras-contrib/blob/master/keras_contrib/losses/jaccard.py#L33

there is another function called Jacard index, you can have a look.

@jizhang02
Copy link

hello,
I run U-Net using dice loss, but the predicted images are all white. Do you know what's wrong?
def dice_coef(y_true, y_pred):
smooth = 1
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection +smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) +smooth)

def dice_coef_loss(y_true, y_pred):
print("dice loss")
return 1-dice_coef(y_true, y_pred)
....
model.compile(optimizer = Adam(lr = 1e-5), loss = dice_coef_loss, metrics = ['accuracy'])

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