class_docstr: Criterion that computes Focal loss.
  
  According to :cite:`lin2018focal`, the Focal loss is computed as follows:
  
  .. math::
  
      \text{FL}(p_t) = -\alpha_t (1 - p_t)^{\gamma} \, \text{log}(p_t)
  
  where:
     - :math:`p_t` is the model's estimated probability for each class.
  
  Args:
      alpha: Weighting factor :math:`\alpha \in [0, 1]`.
      gamma: Focusing parameter :math:`\gamma >= 0`.
      reduction: Specifies the reduction to apply to the
        output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
        will be applied, ``'mean'``: the sum of the output will be divided by
        the number of elements in the output, ``'sum'``: the output will be
        summed.
      pos_weight: a weight of positive examples with shape :math:`(num\_of\_classes,)`.
        It is possible to trade off recall and precision by adding weights to positive examples.
      weight: weights for classes with shape :math:`(num\_of\_classes,)`.
  
  Shape:
      - Pred: :math:`(N, C, *)` where C = number of classes.
      - Target: the same shape as Pred :math:`(N, C, *)`
        where each value is between 0 and 1.
  
  Examples:
      >>> C = 3  # num_classes
      >>> pred = torch.randn(1, C, 5, requires_grad=True)
      >>> target = torch.randint(2, (1, C, 5))
      >>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'}
      >>> criterion = BinaryFocalLossWithLogits(**kwargs)
      >>> output = criterion(pred, target)
      >>> output.backward()
class_docstr_tok: ["Criterion","that","computes","Focal","loss",".","According","to",":","cite",":","`","lin2018focal","`",",","the","Focal","loss","is","computed","as","follows",":","..","math",":",":","\\text","{","FL","}","(","p_t",")","=","-\\alpha_t","(","1","-","p_t",")","^","{","\\gamma","}","\\",",","\\text","{","log","}","(","p_t",")","where",":","-",":","math",":","`","p_t","`","is","the","model","'s","estimated","probability","for","each","class",".","Args",":","alpha",":","Weighting","factor",":","math",":","`","\\alpha","\\in","[","0",",","1","]","`",".","gamma",":","Focusing","parameter",":","math",":","`","\\gamma",">","=","0","`",".","reduction",":","Specifies","the","reduction","to","apply","to","the","output",":","``","'none","'","``","|","``","'mean","'","``","|","``","'sum","'","``",".","``","'none","'","``",":","no","reduction","will","be","applied",",","``","'mean","'","``",":","the","sum","of","the","output","will","be","divided","by","the","number","of","elements","in","the","output",",","``","'sum","'","``",":","the","output","will","be","summed",".","pos_weight",":","a","weight","of","positive","examples","with","shape",":","math",":","`","(","num\\_of\\_classes",",",")","`",".","It","is","possible","to","trade","off","recall","and","precision","by","adding","weights","to","positive","examples",".","weight",":","weights","for","classes","with","shape",":","math",":","`","(","num\\_of\\_classes",",",")","`",".","Shape",":","-","Pred",":",":","math",":","`","(","N",",","C",",","*",")","`","where","C","=","number","of","classes",".","-","Target",":","the","same","shape","as","Pred",":","math",":","`","(","N",",","C",",","*",")","`","where","each","value","is","between","0","and","1",".","Examples",":",">",">",">","C","=","3","#","num_classes",">",">",">","pred","=","torch.randn","(","1",",","C",",","5",",","requires_grad=True",")",">",">",">","target","=","torch.randint","(","2",",","(","1",",","C",",","5",")",")",">",">",">","kwargs","=","{","``","alpha","''",":","0.25",",","``","gamma","''",":","2.0",",","``","reduction","''",":","'mean","'","}",">",">",">","criterion","=","BinaryFocalLossWithLogits","(","*","*","kwargs",")",">",">",">","output","=","criterion","(","pred",",","target",")",">",">",">","output.backward","(",")"]
code: def __init__(
      self,
      alpha: Optional[float],
      gamma: float = 2.0,
      reduction: str = "none",
      pos_weight: Optional[Tensor] = None,
      weight: Optional[Tensor] = None,
  ) -> None:
      super().__init__()
      self.alpha: Optional[float] = alpha
      self.gamma: float = gamma
      self.reduction: str = reduction
      self.pos_weight: Optional[Tensor] = pos_weight
      self.weight: Optional[Tensor] = weight
  
file_path: kornia/kornia/losses/focal.py
imports: from __future__ import annotations
  from typing import Optional
  import torch
  from torch import nn
  from kornia.core import Tensor, tensor
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SHAPE
  from kornia.utils.one_hot import one_hot
label_desc: Use image node_id 1 to create a new BinaryFocalLossWithLogits object from inherited base classes: nn with example: obj = BinaryFocalLossWithLogits(alpha, gamma, reduction, pos_weight, weight)