title: Keras/Tensorflow: Combined Loss function for single output
body: <p>I have only one output for my model, but I would like to combine two different loss functions:</p>
  
  <pre><code>def get_model():
      # create the model here
      model = Model(inputs=image, outputs=output)
  
      alpha = 0.2
      model.compile(loss=[mse, gse],
                        loss_weights=[1-alpha, alpha]
                        , ...)
  </code></pre>
  
  <p>but it complains that I need to have two outputs because I defined two losses:</p>
  
  <pre><code>ValueError: When passing a list as loss, it should have one entry per model outputs. 
  The model has 1 outputs, but you passed loss=[&lt;function mse at 0x0000024D7E1FB378&gt;, &lt;function gse at 0x0000024D7E1FB510&gt;]
  </code></pre>
  
  <p>Can I possibly write my final loss function without having to create another loss function (because that would restrict me from changing the alpha outside the loss function)? </p>
  
  <p><strong>How do I do something like <code>(1-alpha)*mse + alpha*gse</code>?</strong></p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>Both my loss functions are equivalent to the function signature of any builtin keras loss function, takes in <code>y_true</code> and <code>y_pred</code> and gives a tensor back for loss (which can be reduced to a scalar using <code>K.mean()</code>), but I believe, how these loss functions are defined shouldn't affect the answer as long as they return valid losses.</p>
  
  <pre><code>def gse(y_true, y_pred):
      # some tensor operation on y_pred and y_true
      return K.mean(K.square(y_pred - y_true), axis=-1)
  </code></pre>