code: def categorical_focal_loss(
      gt, pr, gamma=2.0, alpha=0.25, class_indexes=None, **kwargs
  ):
      r"""Implementation of Focal Loss from the paper in multiclass classification
  
      Formula:
          loss = - gt * alpha * ((1 - pr)^gamma) * log(pr)
  
      Args:
          gt: ground truth 4D keras tensor (B, H, W, C) or (B, C, H, W)
          pr: prediction 4D keras tensor (B, H, W, C) or (B, C, H, W)
          alpha: the same as weighting factor in balanced cross entropy, default 0.25
          gamma: focusing parameter for modulating factor (1-p), default 2.0
          class_indexes: Optional integer or list of integers, classes to consider, if ``None`` all classes are used.
  
      """
  
      backend = kwargs["backend"]
      gt, pr = gather_channels(gt, pr, indexes=class_indexes, **kwargs)
  
      # clip to prevent NaN's and Inf's
      pr = backend.clip(pr, backend.epsilon(), 1.0 - backend.epsilon())
  
      # Calculate focal loss
      loss = -gt * (
          alpha * backend.pow((1 - pr), gamma) * backend.log(pr)
      )
  
      return backend.mean(loss)
  
file_path: segmentation_models/segmentation_models/base/functional.py
label_desc: Use image node_id 12 for calling a global function with example usage: categorical_focal_loss(gt, pr, gamma, alpha, class_indexes) and returns: backend