title: Keras custom loss different shapes of `ypred` and `ytrue`
body: <p>I would like to implement a custom loss for a model I am training. The goal of the model is to create a box which separates two classes. The output of the model is 3 floats, which define the edges of the box.</p>
  <p>I would like a loss function that works something like this:</p>
  <pre><code># ytrue has shape [batch, 2, 64, 64, 64]
  # ypred has shape [batch, 3]
  def custom_loss(ytrue, ypred):
      class0_locations = ytrue[:,0]
      class1_locations = ytrue[:,1]
  
      # penalize class1 outside box and class 0 inside box
      class1_outside = f1(class1_locations, ypred)
      class0_inside  = f2(class0_locations, ypred)
  
      return class1_outside + class0_inside
  </code></pre>
  <p>However, this does not work as Keras does not like losses with different shapes for <code>ytrue</code> and <code>ypred</code> (see <a href="https://keras.io/api/losses/" rel="nofollow noreferrer">https://keras.io/api/losses/</a>). Can anyone help me with this?</p>