title: Keras custom loss per one instance
body: <p>Here is the original dice function:</p>
  
  <pre><code>def dice_coefficient_(y_true, y_pred):
      y_true_f = K.flatten(y_true)
      y_pred_f = K.flatten(y_pred)
      intersection = K.sum(K.abs(y_true_f * y_pred_f), axis=-1)
  
      return (2. * intersection) / (
          K.sum(K.square(y_true_f), -1) + K.sum(K.square(y_pred_f), -1) + 1e-8)
  </code></pre>
  
  <p>The shape of y_true and y_pred : (batch size, 1, 128, 160, 128)</p>
  
  <p>Loss = -1 * dice_coefficient</p>
  
  <p><strong>I'm trying to edit the function so that it calculates a loss value per one instance and returns the averaged values.</strong></p>
  
  <p>The reason i want to edit this is that the current function is affected by batch size. When batch size increases, dice increases also.</p>
  
  <p><strong>How do i edit the code in this case?</strong> I tried to use for loop but a person said "Don't use for loop.".</p>