Answers.Body: <p>Mixing loss functions is very possible.  For example, in the case of <a href="https://www.tensorflow.org/tutorials/generative/style_transfer" rel="nofollow noreferrer">neural style transfer</a>, there is a style loss and a content loss. Both of them are backpropagated through the network. The final loss used for the backpropagation is a weighted sum of the losses. In the case of style transfer, it ensures that the image generated is not only imitating the style of the style image, but also keeping the original content. Sometimes there is also a third loss called variation loss. This is also applied to a weight and summed. Note the weight is a hyperparameter and is not changed during training. Also, the loss should not measure the same purpose, but rather a different purpose that you want to optimize together. Example code using PyTorch:</p>
  
  <pre><code>loss1 = torch.nn.MSELoss(a,b)
  loss2 = torch.nn.MSELoss(b,c)
  loss = loss1 * alpha + loss2 * beta
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-20T23:21:02.700Z
Answers.LastActivityDate: 2019-10-22T00:47:03.753Z
Answers.LastEditDate: 2019-10-22T00:47:03.753Z
Answers.UserDisplayName: Clement
Body: <p>I am trying to understand the best loss function to be used with a convolutional neural network. I came to know that we can <a href="https://ai.stackexchange.com/questions/13324/what-is-the-best-loss-function-for-convolution-neural-network-and-autoencoder">mix two loss functions</a>. Can any body share in what case was it done and how?</p>
  
Tags: <convolutional-neural-networks><backpropagation><objective-functions>
Title: When and how to use a mix of loss functions for back-propagation?
UserDisplayName: M4NI5H
ThreadText: # When and how to use a mix of loss functions for back-propagation?
  
  (Asked by: username_0 on 2019-10-15)
  
  I am trying to understand the best loss function to be used with a convolutional neural network. I came to know that we can [mix two loss functions](https://ai.stackexchange.com/questions/13324/what-is-the-best-loss-function-for-convolution-neural-network-and-autoencoder). Can any body share in what case was it done and how?
  
  **Tags:** convolutional-neural-networks, backpropagation, objective-functions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-20. Score: 1
  
  Mixing loss functions is very possible. For example, in the case of [neural style transfer](https://www.tensorflow.org/tutorials/generative/style_transfer), there is a style loss and a content loss. Both of them are backpropagated through the network. The final loss used for the backpropagation is a weighted sum of the losses. In the case of style transfer, it ensures that the image generated is not only imitating the style of the style image, but also keeping the original content. Sometimes there is also a third loss called variation loss. This is also applied to a weight and summed. Note the weight is a hyperparameter and is not changed during training. Also, the loss should not measure the same purpose, but rather a different purpose that you want to optimize together. Example code using PyTorch:
  
  ```
  loss1 = torch.nn.MSELoss(a,b)
  loss2 = torch.nn.MSELoss(b,c)
  loss = loss1 * alpha + loss2 * beta
  
  ```
  
  
  ---
  
  