import tensorflow as tf

             margin=margin,
             use_semi_hard=use_semi_hard,
             anchor_positive_mining_distances=anchor_positive_mining_distances,
             anchor_match_mining_distance_matrix=(
                 anchor_match_mining_distance_matrix)))
    negative_distances = tf.boolean_mask(
        negative_distances,
        mask=negative_distances < negative_distances.dtype.max)
    negative_mining_distances = tf.boolean_mask(
        negative_mining_distances,
        mask=negative_distances < negative_distances.dtype.max)

    active_triplet_ratio = (
        tf.cast(num_active_triplets, dtype=tf.float32) / num_total_triplets)
    active_mining_triplet_ratio = (
        tf.cast(num_active_mining_triplets, dtype=tf.float32) /
        num_total_triplets)

    active_loss = (
        loss / tf.math.maximum(1e-12, tf.stop_gradient(active_triplet_ratio)))
    active_mining_loss = (
        mining_loss /
        tf.math.maximum(1e-12, tf.stop_gradient(active_mining_triplet_ratio)))

    tag = 'SemiHardNegative' if use_semi_hard else 'HardNegative'
    summaries = {
