Skip to content

Instantly share code, notes, and snippets.

@stiv-yakovenko
Created June 12, 2019 22:25
Show Gist options
  • Save stiv-yakovenko/cb8ad7e9a2e922f23c44b04777c5aa02 to your computer and use it in GitHub Desktop.
Save stiv-yakovenko/cb8ad7e9a2e922f23c44b04777c5aa02 to your computer and use it in GitHub Desktop.

Revisions

  1. stiv-yakovenko created this gist Jun 12, 2019.
    8 changes: 8 additions & 0 deletions bce_and_dice.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    smooth = 1.
    intersection = tf.reduce_sum(flat_logits * flat_labels)
    dice_score = (2 * intersection + smooth) / (
    tf.reduce_sum(flat_labels) + tf.reduce_sum(flat_logits) + smooth)
    dice_loss = 1 - dice_score
    cross_entropy_loss = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits_v2(logits=flat_logits, labels=flat_labels))
    loss = dice_loss + cross_entropy_loss