def batch_alpha_balance_loss(labels, loss):
    """
    Calculate the alpha balanced cross_entropy.

    This means for each sample the cross entropy is calculated and then weighted by the class specific weight.

    There is yet no paper for this type of loss.

    :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities.
    :param loss: A float tensor of shape [batch_size, ...] representing the loss that should be focused.
    :return: A tensor representing the weighted cross entropy.
    """
    with tf.variable_scope("batch_alpha_balance"):
        # Compute the occurrence probability for each class
        mu, _ = tf.nn.moments(labels, [0, 1, 2])

        # For weighting a class should be down weighted by its occurrence probability.
        not_mu = 1 - mu

        # Select the class specific not_mu
        not_mu_class = tf.reduce_sum(labels * not_mu, axis=-1)
        return not_mu_class * loss
def batch_alpha_balance_loss ( labels , loss ) : with tf . variable_scope ( "batch_alpha_balance" ) : mu , _ = tf . nn . moments ( labels , [ 0 , 1 , 2 ] ) not_mu = 1 - mu not_mu_class = tf . reduce_sum ( labels * not_mu , axis = - 1 ) return not_mu_class * loss
Calculate the alpha balanced cross_entropy.

    This means for each sample the cross entropy is calculated and then weighted by the class specific weight.

    There is yet no paper for this type of loss.

    :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities.
    :param loss: A float tensor of shape [batch_size, ...] representing the loss that should be focused.
    :return: A tensor representing the weighted cross entropy.