docstr: :param alpha: Prior probability of having positive value in target.
  :param gamma: Power factor for dampening weight (focal strength).
  :param ignore_index: If not None, targets may contain values to be ignored.
  Target values equal to ignore_index will be ignored from loss computation.
  :param reduced: Switch to reduced focal loss. Note, when using this mode you should use `reduction="sum"`.
  :param activation: Either `sigmoid` or `softmax`. If `softmax` is used, `softmax_dim` must be also specified.
docstr_tok: [":","param","alpha",":","Prior","probability","of","having","positive","value","in","target",".",":","param","gamma",":","Power","factor","for","dampening","weight","(","focal","strength",")",".",":","param","ignore_index",":","If","not","None",",","targets","may","contain","values","to","be","ignored",".","Target","values","equal","to","ignore_index","will","be","ignored","from","loss","computation",".",":","param","reduced",":","Switch","to","reduced","focal","loss",".","Note",",","when","using","this","mode","you","should","use","`","reduction=","''","sum","''","`",".",":","param","activation",":","Either","`","sigmoid","`","or","`","softmax","`",".","If","`","softmax","`","is","used",",","`","softmax_dim","`","must","be","also","specified","."]
code: def __init__(
      self,
      alpha: Optional[float] = None,
      gamma: float = 2.0,
      ignore_index: Optional[int] = None,
      reduction: str = "mean",
      normalized: bool = False,
      reduced_threshold: Optional[float] = None,
      activation: str = "sigmoid",
      softmax_dim: Optional[int] = None,
  ):
      """
  
      :param alpha: Prior probability of having positive value in target.
      :param gamma: Power factor for dampening weight (focal strength).
      :param ignore_index: If not None, targets may contain values to be ignored.
      Target values equal to ignore_index will be ignored from loss computation.
      :param reduced: Switch to reduced focal loss. Note, when using this mode you should use `reduction="sum"`.
      :param activation: Either `sigmoid` or `softmax`. If `softmax` is used, `softmax_dim` must be also specified.
  
      """
      super().__init__()
      self.alpha = alpha
      self.gamma = gamma
      self.ignore_index = ignore_index
      self.reduction = reduction
      self.normalized = normalized
      self.reduced_threshold = reduced_threshold
      self.activation = activation
      self.softmax_dim = softmax_dim
  
      self.focal_loss_fn = partial(
          focal_loss_with_logits,
          alpha=alpha,
          gamma=gamma,
          reduced_threshold=reduced_threshold,
          reduction=reduction,
          normalized=normalized,
          ignore_index=ignore_index,
          activation=activation,
          softmax_dim=softmax_dim,
      )
  
      self.get_one_hot_targets = (
          self._one_hot_targets_with_ignore
          if ignore_index is not None
          else self._one_hot_targets
      )
  
file_path: pytorch-toolbelt/pytorch_toolbelt/losses/focal.py
imports: from functools import partial
  from typing import Optional
  import torch
  from torch import Tensor, nn
  from torch.nn.modules.loss import _Loss
  from .functional import focal_loss_with_logits, softmax_focal_loss_with_logits
  from pytorch_toolbelt.utils import pytorch_toolbelt_deprecated
label_desc: Use image node_id 1 to create a new BinaryFocalLoss object from inherited base classes: nn with example: obj = BinaryFocalLoss(alpha, gamma, ignore_index, reduction, normalized, reduced_threshold, activation, softmax_dim)