title: How to correctly define loss function in keras network that takes an image and outputs an image?
body: <p>I'm trying to build a model that takes grayscale image and generates another image as output by residual CNN using keras. And the key idea here is that the amount of non-white pixels is way smaller than the amount of white ones. So the error in each non-white pixel should have more weight in the loss function than in the white one. And the darker the pixel the bigger error should be. 
  That's how I've done it presently.
  Here, total_pred_score means all the correctly guessed pixels with their weights defined by some int coefficient and total_true_score means the total expected score for all images and pixels in the train set.
  But I'm not sure it's right.Can you help me please?</p>
  
  <pre class="lang-py prettyprint-override"><code>def custom_loss(y_true, y_pred):
      y_true1, y_pred1 = (255 - y_true) / 255, (255 - y_pred) / 255
      dif = (1 - K.abs(y_true1 - y_pred1))
      weight = (coeff - 1) * y_true1 + 1 
      total_true_score = K.sum(weight, axis = [0,1,2,3])
      total_pred_score = K.sum(multiply([dif,weight]), axis = [0,1,2,3])
      return K.abs(total_true_score - total_pred_score) / total_true_score
  </code></pre>