title: Good performance with Accuracy but not with Dice loss in Image Segmentation
body: <p>I'm doing image segmentation with U-Net like architecture on Tensorflow w/Keras but I'm new in Deep Learning.<br>
  I've got this dataset with the following set shapes:</p>
  
  <ul>
  <li>Train : X : (175250, 30, 30, 6) Y: (175250, 30, 30)</li>
  <li>Validation:  X: (29200, 30, 30, 6) Y: (29200, 30, 30)</li>
  <li>Test :  X: (29200, 30, 30, 6) Y: (29200, 30, 30)</li>
  </ul>
  
  <p>Got some examples of these images and each channel, further down.</p>
  
  <p>--> with 20% positive examples and 80% negative examples equally in each set</p>
  
  <p>I run some series but for the best filter combination it made
  the plot for BCE with good accuracy:
  <a href="https://i.stack.imgur.com/y03Kx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y03Kx.png" alt="enter image description here"></a></p>
  
  <p>The plot for custom functions, Dice_Loss by Dice_Coeff:</p>
  
  <p><a href="https://i.stack.imgur.com/YpcdN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YpcdN.png" alt="enter image description here"></a></p>
  
  <p>And some images generated from the best model trained with test images: </p>
  
  <p><a href="https://i.stack.imgur.com/1YLBH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1YLBH.png" alt="enter image description here"></a></p>
  
  <p>The problem is when I change to dice loss and coefficient, there aren´t good predictions as we seen in the image plot and now it isn´t in the image prediction as we may see.
  <a href="https://i.stack.imgur.com/oxqqz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oxqqz.png" alt="enter image description here"></a></p>
  
  <p>Why it performs so badly in the dice loss? What other function do you recommend?</p>
  
  <p>My dice loss and coefficient function:</p>
  
  <blockquote>
  <pre><code>def dice_coeff(y_true, y_pred, smooth=1):
      intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
      return (2. * intersection + smooth) / (K.sum(K.square(y_true),-1) + K.sum(K.square(y_pred),-1) + smooth)
  
  
  def dice_loss(y_true, y_pred):
      return 1-dice_coeff(y_true, y_pred)
  </code></pre>
  </blockquote>