class_docstr: Focal loss based on https://github.com/AdeelH/pytorch-multi-class-focal-loss/blob/master/focal_loss.py
  
  References:
      [1] https://arxiv.org/abs/1708.02002
docstr: Parameters
  ----------
  alpha
      weighting factor for each class. Should be of shape (num_classes)
  gamma
      the focal parameter for calculating weights on easy/hard samples
  reduction
      the reduction to apply to the final loss output. Default: "mean". Options:
          "mean", "sum"
  eps
      epsilon for numerical stability
docstr_tok: ["Parameters","--","--","--","--","--","alpha","weighting","factor","for","each","class",".","Should","be","of","shape","(","num_classes",")","gamma","the","focal","parameter","for","calculating","weights","on","easy\/hard","samples","reduction","the","reduction","to","apply","to","the","final","loss","output",".","Default",":","``","mean","''",".","Options",":","``","mean","''",",","``","sum","''","eps","epsilon","for","numerical","stability"]
code: def __init__(
      self,
      alpha: Optional[torch.Tensor] = None,
      gamma: Optional[float] = 2.0,
      reduction: Optional[str] = "mean",
      eps: Optional[float] = 1e-6,
  ):
      """
  
      Parameters
      ----------
      alpha
          weighting factor for each class. Should be of shape (num_classes)
      gamma
          the focal parameter for calculating weights on easy/hard samples
      reduction
          the reduction to apply to the final loss output. Default: "mean". Options:
              "mean", "sum"
      eps
          epsilon for numerical stability
      """
      super(FocalLoss, self).__init__()
  
      self.gamma = gamma
      self.reduction = reduction
      self.eps = eps
      if alpha is not None:
          if isinstance(
              alpha, str
          ):  # handles Ray Tune HPO sampled hyperparameter
              try:
                  numbers = alpha.strip("()").split(",")
                  alpha = [float(num) for num in numbers]
              except:
                  raise ValueError(
                      f"{type(alpha)} {alpha} is not in a supported format."
                  )
          alpha = torch.tensor(alpha)
      self.nll_loss = nn.NLLLoss(weight=alpha, reduction="none")
  
imports: import logging
  from typing import Optional
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new FocalLoss object from inherited base classes: nn with example: obj = FocalLoss(alpha, gamma, reduction, eps)