title: Keras custom loss function with multiple output model
body: <p>In a segmentation task I wanted to have my model to have two outputs because I implemented weight maps as suggested in the original U-net paper <a href="https://arxiv.org/pdf/1505.04597.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1505.04597.pdf</a>.</p>
  <p>As per the suggestion I created weightmaps concentrating some of the ground truth mask to have higher weights. Now I have a model with.</p>
  <pre><code>weightmap=layers.Lambda(lambda x:x)(weight_map) # A non trainable layer to output this as tensor for loss function
  Model=model(inputs=[input,weight_map], outputs=[output,weightmap]
  </code></pre>
  <p>Now I need to compute binary cross entropy loss for the following model</p>
  <pre><code>def custom_loss(target,outputs):
      loss=K.binary_crossentropy(target,outputs[0]) #ouputs[0] should be the model output
      loss=loss*outputs[1] #outputs[1] should be weightmaps 
      return loss 
  </code></pre>
  <p>This output[0] and output[1] slicing of output tensor from model doesnt work.</p>
  <p>Is there anything I can do to implement the following with both outputs of model in a single loss function?</p>