code: def variance_corrected_loss(loss, sigma_2=None):
      
      with tf.variable_scope("variance_corrected_loss"):
          sigma_cost = 0
          if sigma_2 is None:
              # FIXME the paper has been updated Apr 2018, check if implementation is still valid.
              sigma = tf.get_variable(name="sigma", dtype=tf.float32, initializer=tf.constant(1.0), trainable=True)
              sigma_2 = tf.pow(sigma, 2)
              tf.summary.scalar("sigma2", sigma_2)
              sigma_cost = tf.log(sigma_2 + 1.0)
          return 0.5 / sigma_2 * loss + sigma_cost
docs: Create a variance corrected loss.
  
      When summing variance corrected losses you get the same as multiloss.
      This is especially usefull for keras where when having multiple losses they are summed by keras.
      This multi-loss implementation is inspired by the Paper "Multi-Task Learning Using Uncertainty to Weight Losses
      for Scene Geometry and Semantics" by Kendall, Gal and Cipolla.
      :param loss: The loss that should be variance corrected.
      :param sigma_2: Optional a variance (sigma squared) to use. If none is provided it is learned.
      :return: The variance corrected loss.