def _div_maybe_zero(total_loss, num_present):
  """Normalizes the total loss with the number of present pixels."""
  return tf.cast(num_present > 0, tf.float32) * tf.math.divide(
      total_loss, tf.maximum(1e-5, num_present))