def triplet_loss(anchor, positive, negative, alpha):
 with tf.variable_scope('triplet_loss'):
  pos_dist = tf.reduce_sum(tf.square(tf.sub(anchor, positive)), 1)
  neg_dist = tf.reduce_sum(tf.square(tf.sub(anchor, negative)), 1)
  basic_loss = tf.add(tf.sub(pos_dist, neg_dist), alpha)
  loss = tf.reduce_mean(tf.maximum(basic_loss, 0.0), 0)
 return loss

def triplet_loss ( anchor , positive , negative , alpha ) : with tf . variable_scope ( 'triplet_loss' ) : pos_dist = tf . reduce_sum ( tf . square ( tf . sub ( anchor , positive ) ) , 1 ) neg_dist = tf . reduce_sum ( tf . square ( tf . sub ( anchor , negative ) ) , 1 ) basic_loss = tf . add ( tf . sub ( pos_dist , neg_dist ) , alpha ) loss = tf . reduce_mean ( tf . maximum ( basic_loss , 0.0 ) , 0 ) return loss
calculate the triplet loss according to the facenet paper args: anchor: the embeddings for the anchor images .