import tensorflow as tf

    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 = {
        # Summaries related to triplet loss computation.
        'triplet_loss/Anchor/%s/Distance/Mean' % tag:
            tf.math.reduce_mean(negative_distances),
        'triplet_loss/%s/Loss/All' % tag:
            loss,
        'triplet_loss/%s/Loss/Active' % tag:
            active_loss,
        'triplet_loss/%s/ActiveTripletNum' % tag:
            num_active_triplets,
        'triplet_loss/%s/ActiveTripletRatio' % tag:
            active_triplet_ratio,

        # Summaries related to triplet mining.
        'triplet_mining/Anchor/%s/Distance/Mean' % tag:
            tf.math.reduce_mean(negative_mining_distances),
        'triplet_mining/%s/Loss/All' % tag:
