def distance_weighted_triplet_loss(labels, embeddings, margin=1.0, squared=False, high_var_threshold=0.5, nonzero_loss_threshold=1.4, neg_multiplier=1):
    'distance weighted sampling + triplet loss\n    Args:\n        labels: 1-D. tf.int32 `Tensor` with shape [batch_size] of multi-class integer labels.\n        embeddings: 2-D float `Tensor` of embedding vectors. Embeddings should be l2 normalized.\n        margin: Float, margin term in the loss function.\n        squared: Boolean, whether or not to square the triplet distances.\n        nu: float. Regularization parameter for beta.\n        high_var_threshold: float. cutoff for high gradient variance.\n        nonzero_loss_threshold: float. cutoff for non-zero loss zone.\n        neg_multiplier: int, default=1. the multiplier to enlarger the negative and positive samples.\n    Returns:\n        triplet_loss: tf.float32 scalar\n\n    '
    (a_indices, anchors, positives, negatives) = dist_weighted_sampling(labels, embeddings, high_var_threshold=high_var_threshold, nonzero_loss_threshold=nonzero_loss_threshold, neg_multiplier=neg_multiplier)
    d_ap = tf.reduce_sum(tf.square((positives - anchors)), axis=1)
    d_an = tf.reduce_sum(tf.square((negatives - anchors)), axis=1)
    if (not squared):
        d_ap = K.sqrt((d_ap + 1e-16))
        d_an = K.sqrt((d_an + 1e-16))
    loss = tf.maximum(((d_ap - d_an) + margin), 0)
    loss = tf.reduce_mean(loss)
    return loss
distance weighted sampling + triplet loss
Args:
    labels: 1-D. tf.int32 `Tensor` with shape [batch_size] of multi-class integer labels.
    embeddings: 2-D float `Tensor` of embedding vectors. Embeddings should be l2 normalized.
    margin: Float, margin term in the loss function.
    squared: Boolean, whether or not to square the triplet distances.
    nu: float. Regularization parameter for beta.
    high_var_threshold: float. cutoff for high gradient variance.
    nonzero_loss_threshold: float. cutoff for non-zero loss zone.
    neg_multiplier: int, default=1. the multiplier to enlarger the negative and positive samples.
Returns:
    triplet_loss: tf.float32 scalar
def distance_weighted_triplet_loss(labels, embeddings, margin=1.0, squared=False, high_var_threshold=0.5, nonzero_loss_threshold=1.4, neg_multiplier=1):
    'distance weighted sampling + triplet loss\n    Args:\n        labels: 1-D. tf.int32 `Tensor` with shape [batch_size] of multi-class integer labels.\n        embeddings: 2-D float `Tensor` of embedding vectors. Embeddings should be l2 normalized.\n        margin: Float, margin term in the loss function.\n        squared: Boolean, whether or not to square the triplet distances.\n        nu: float. Regularization parameter for beta.\n        high_var_threshold: float. cutoff for high gradient variance.\n        nonzero_loss_threshold: float. cutoff for non-zero loss zone.\n        neg_multiplier: int, default=1. the multiplier to enlarger the negative and positive samples.\n    Returns:\n        triplet_loss: tf.float32 scalar\n\n    '
    (a_indices, anchors, positives, negatives) = dist_weighted_sampling(labels, embeddings, high_var_threshold=high_var_threshold, nonzero_loss_threshold=nonzero_loss_threshold, neg_multiplier=neg_multiplier)
    d_ap = tf.reduce_sum(tf.square((positives - anchors)), axis=1)
    d_an = tf.reduce_sum(tf.square((negatives - anchors)), axis=1)
    if (not squared):
        d_ap = K.sqrt((d_ap + 1e-16))
        d_an = K.sqrt((d_an + 1e-16))
    loss = tf.maximum(((d_ap - d_an) + margin), 0)
    loss = tf.reduce_mean(loss)
    return loss