class_docstr: References:
      Author: clcarwin
      Site https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py
class_docstr_tok: ["References",":","Author",":","clcarwin","Site","https",":","\/\/github.com\/clcarwin\/focal_loss_pytorch\/blob\/master\/focalloss.py"]
code: def forward(self, input, target):
      if input.dim() > 2:
          input = input.view(
              input.size(0), input.size(1), -1
          )  # N,C,H,W => N,C,H*W
          input = input.transpose(1, 2)  # N,C,H*W => N,H*W,C
          input = input.contiguous().view(
              -1, input.size(2)
          )  # N,H*W,C => N*H*W,C
      target = target.view(-1, 1)
  
      logpt = F.log_softmax(input, dim=1)
      logpt = logpt.gather(1, target)
      logpt = logpt.view(-1)
      pt = logpt.data.exp()
  
      if self.alpha is not None:
          if self.alpha.type() != input.data.type():
              self.alpha = self.alpha.type_as(input.data)
          select = (
              (target != 0).type(torch.LongTensor).to(self.alpha.device)
          )
          at = self.alpha.gather(0, select.data.view(-1))
          logpt = logpt * at
  
      loss = -1 * (1 - pt) ** self.gamma * logpt
      if self.size_average:
          return loss.mean()
      else:
          return loss.sum()
  
file_path: baal/experiments/segmentation/utils.py
imports: from typing import List
  import numpy
  import segmentation_models_pytorch
  from segmentation_models_pytorch.base.modules import Activation
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision import datasets
  from torchvision.transforms import transforms
  from baal import ActiveLearningDataset
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, loss