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
code: def forward(self, input: torch.Tensor, target: torch.Tensor):
      if not torch.is_tensor(input):
          raise TypeError(
              "input type is not a torch.Tensor. Got {}".format(
                  type(input)
              )
          )
      if input.ndim > 2:
          # (N, C, d1, d2, ..., dK) --> (N * d1 * ... * dK, C)
          num_class = input.shape[1]
          input = input.permute(0, *range(2, input.ndim), 1).reshape(
              -1, num_class
          )
          # (N, d1, d2, ..., dK) --> (N * d1 * ... * dK,)
          target = target.view(-1)
  
      pt = F.softmax(input, dim=-1)
  
      # -alpha_t * log(pt) term
      log_p = torch.log_softmax(input, dim=-1)
      ce = self.nll_loss(log_p, target)
  
      # (1 - pt)^gamma term
      all_rows = torch.arange(input.shape[0])
      pt = pt[all_rows, target]
      focal_term = (1 - pt) ** self.gamma
  
      loss = focal_term * ce
  
      if self.reduction == "mean":
          loss = loss.mean()
  
      elif self.reduction == "sum":
          loss = loss.sum()
  
      return loss
  
imports: import logging
  from typing import Optional
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 2 for calling the FocalLoss obj's underlying member method code with example usage: obj.forward(input, target) and returns: loss