code: def sigmoid_focal_crossentropy(
      y_true: TensorLike,
      y_pred: TensorLike,
      alpha: FloatTensorLike = 0.25,
      gamma: FloatTensorLike = 2.0,
      from_logits: bool = False,
  ) -> tf.Tensor:
      """Implements the focal loss function.
  
      Focal loss was first introduced in the RetinaNet paper
      (https://arxiv.org/pdf/1708.02002.pdf). Focal loss is extremely useful for
      classification when you have highly imbalanced classes. It down-weights
      well-classified examples and focuses on hard examples. The loss value is
      much higher for a sample which is misclassified by the classifier as compared
      to the loss value corresponding to a well-classified example. One of the
      best use-cases of focal loss is its usage in object detection where the
      imbalance between the background class and other classes is extremely high.
  
      Args:
          y_true: true targets tensor.
          y_pred: predictions tensor.
          alpha: balancing factor.
          gamma: modulating factor.
  
      Returns:
          Weighted loss float `Tensor`. If `reduction` is `NONE`,this has the
          same shape as `y_true`; otherwise, it is scalar.
      """
      if gamma and gamma < 0:
          raise ValueError(
              "Value of gamma should be greater than or equal to zero."
          )
  
      y_pred = tf.convert_to_tensor(y_pred)
      y_true = tf.cast(y_true, dtype=y_pred.dtype)
  
      # Get the cross_entropy for each entry
      ce = K.binary_crossentropy(
          y_true, y_pred, from_logits=from_logits
      )
  
      # If logits are provided then convert the predictions into probabilities
      if from_logits:
          pred_prob = tf.sigmoid(y_pred)
      else:
          pred_prob = y_pred
  
      p_t = (y_true * pred_prob) + ((1 - y_true) * (1 - pred_prob))
      alpha_factor = 1.0
      modulating_factor = 1.0
  
      if alpha:
          alpha = tf.cast(alpha, dtype=y_true.dtype)
          alpha_factor = y_true * alpha + (1 - y_true) * (1 - alpha)
  
      if gamma:
          gamma = tf.cast(gamma, dtype=y_true.dtype)
          modulating_factor = tf.pow((1.0 - p_t), gamma)
  
      # compute the final loss and return
      return tf.reduce_sum(
          alpha_factor * modulating_factor * ce, axis=-1
      )
  
file_path: addons/tensorflow_addons/losses/focal_loss.py
imports: import tensorflow
  import tensorflow.keras.backend
  from typeguard import typechecked
  from tensorflow_addons.utils.keras_utils import LossFunctionWrapper
  from tensorflow_addons.utils.types import FloatTensorLike, TensorLike
label_desc: Use image node_id 1 for calling a global function with example usage: sigmoid_focal_crossentropy(y_true, y_pred, alpha, gamma, from_logits) and returns: tf