docstr: Applies focal loss based on https://arxiv.org/pdf/1708.02002.pdf
docstr_tok: ["Applies","focal","loss","based","on","https",":","\/\/arxiv.org\/pdf\/1708.02002.pdf"]
code: def forward(self, inp: Tensor, targ: Tensor) -> Tensor:
      "Applies focal loss based on https://arxiv.org/pdf/1708.02002.pdf"
      ce_loss = F.cross_entropy(
          inp, targ, weight=self.weight, reduction="none"
      )
      p_t = torch.exp(-ce_loss)
      loss = (1 - p_t) ** self.gamma * ce_loss
      if self.reduction == "mean":
          loss = loss.mean()
      elif self.reduction == "sum":
          loss = loss.sum()
      return loss
  
imports: from __future__ import annotations
  from .imports import *
  from .torch_imports import *
  from .torch_core import *
  from .layers import *
label_desc: Use image node_id 2 for calling the FocalLoss obj's underlying member method code with example usage: obj.forward(inp, targ) and returns: loss