import tensorflow as tf

            tf.select(cdf_delta > 1e-5, tf.log(tf.maximum(cdf_delta, 1e-12)),
                      log_pdf_mid - np.log(127.5))))

    log_probs = tf.reduce_sum(log_probs, 3) + \
        log_prob_from_logits(logit_probs)
    if sum_all:
      return -tf.reduce_sum(log_sum_exp(log_probs))
    else:
      return -tf.reduce_sum(log_sum_exp(log_probs), [1, 2])


def mse_loss(pred, labels):
  try:
    batch_size = tf.cast(pred.shape[0], tf.float32)
  except Exception as e:
    print('Pred is a tf tensor %s' % str(e.message))
    batch_size = tf.cast(tf.shape(pred)[0], tf.float32)
  loss_val = tf.sqrt(2 * tf.nn.l2_loss(pred - labels)) / batch_size
  return loss_val


def pullaway_loss(embeddings, name='pullaway_loss'):
  """Pull Away loss calculation.

  Args:
      embeddings: The embeddings to be orthogonalized for varied faces.
