import tensorflow as tf

    loss: Loss tensor of type float.
  """
  with tf.name_scope('segment_loss'):
    # logits = tf.reshape(logits, (-1, num_classes))
    epsilon = tf.constant(value=1e-7)
    labels = tf.to_float(labels)
    # labels = tf.to_float(tf.reshape(labels, (-1, num_classes)))

    softmax = tf.nn.softmax(logits) + epsilon

    if head is not None:
      cross_entropy = -tf.reduce_sum(tf.mul(labels * tf.log(softmax), head), axis=[1])
    else:
      cross_entropy = -tf.reduce_sum(labels * tf.log(softmax), axis=[1])

    cross_entropy_mean = tf.reduce_mean(cross_entropy, name='xentropy_mean')
  return cross_entropy_mean


def triplet_loss(anchor, positive, negative, alpha=0.2, name='triplet_loss'):
  """Calculate the triplet loss according to the FaceNet paper.

  Args:
    anchor: 2-D `tensor` [batch_size, embedding_size], the embeddings for the anchor images.
    positive: 2-D `tensor` [batch_size, embedding_size], the embeddings for the positive images.
    negative: 2-D `tensor` [batch_size, embedding_size], the embeddings for the negative images.
    alpha: positive to negative triplet distance margin

  Returns:
    the triplet loss.
