code: def focus_loss(labels, probs, loss, gamma):
      
      with tf.variable_scope("focus_loss"):
          # Compute p_t that is used in paper.
          # FIXME is it possible that the 1-p term does not make any sense?
          p_t = tf.reduce_sum(probs * labels, axis=-1)# + tf.reduce_sum((1.0 - probs) * (1.0 - labels), axis=-1)
  
          focal_factor = tf.pow(1.0 - p_t, gamma) if gamma > 0 else 1  # Improve stability for gamma = 0
          return tf.stop_gradient(focal_factor) * loss
docs: Calculate the alpha balanced focal loss.
  
      See the focal loss paper: "Focal Loss for Dense Object Detection" [by Facebook AI Research]
  
      :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities.
      :param probs: A float tensor of shape [batch_size, ..., num_classes] representing the probs (after softmax).
      :param loss: A float tensor of shape [batch_size, ...] representing the loss that should be focused.
      :param gamma: The focus parameter.
      :return: A tensor representing the weighted cross entropy.