docstr: `Equalization Loss v2 <https://arxiv.org/abs/2012.08548>`_
  
  Args:
      use_sigmoid (bool): EQLv2 uses the sigmoid function to transform
          the predicted logits to an estimated probability distribution.
      reduction (str, optional): The method used to reduce the loss into
          a scalar. Defaults to 'mean'.
      class_weight (Tensor, optional): The weight of loss for each
          prediction. Defaults to None.
      loss_weight (float, optional): The weight of the total EQLv2 loss.
          Defaults to 1.0.
      num_classes (int): 1203 for lvis v1.0, 1230 for lvis v0.5.
      use_distributed (bool, float): EQLv2 will calculate the gradients
          on all GPUs if there is any. Change to True if you are using
          distributed training. Default to False.
      mu (float, optional): Defaults to 0.8
      alpha (float, optional): A balance factor for the negative part of
          EQLV2 Loss. Defaults to 4.0.
      gamma (int, optional): The gamma for calculating the modulating
          factor. Defaults to 12.
      vis_grad (bool, optional): Default to False.
      test_with_obj (bool, optional): Default to True.
  
  Returns:
      None.
docstr_tok: ["`","Equalization","Loss","v2","<","https",":","\/\/arxiv.org\/abs\/2012.08548",">","`","_","Args",":","use_sigmoid","(","bool",")",":","EQLv2","uses","the","sigmoid","function","to","transform","the","predicted","logits","to","an","estimated","probability","distribution",".","reduction","(","str",",","optional",")",":","The","method","used","to","reduce","the","loss","into","a","scalar",".","Defaults","to","'mean","'",".","class_weight","(","Tensor",",","optional",")",":","The","weight","of","loss","for","each","prediction",".","Defaults","to","None",".","loss_weight","(","float",",","optional",")",":","The","weight","of","the","total","EQLv2","loss",".","Defaults","to","1.0.","num_classes","(","int",")",":","1203","for","lvis","v1.0",",","1230","for","lvis","v0.5",".","use_distributed","(","bool",",","float",")",":","EQLv2","will","calculate","the","gradients","on","all","GPUs","if","there","is","any",".","Change","to","True","if","you","are","using","distributed","training",".","Default","to","False",".","mu","(","float",",","optional",")",":","Defaults","to","0.8","alpha","(","float",",","optional",")",":","A","balance","factor","for","the","negative","part","of","EQLV2","Loss",".","Defaults","to","4.0.","gamma","(","int",",","optional",")",":","The","gamma","for","calculating","the","modulating","factor",".","Defaults","to","12.","vis_grad","(","bool",",","optional",")",":","Default","to","False",".","test_with_obj","(","bool",",","optional",")",":","Default","to","True",".","Returns",":","None","."]
code: def __init__(
      self,
      use_sigmoid: bool = True,
      reduction: str = "mean",
      class_weight: Optional[Tensor] = None,
      loss_weight: float = 1.0,
      num_classes: int = 1203,
      use_distributed: bool = False,
      mu: float = 0.8,
      alpha: float = 4.0,
      gamma: int = 12,
      vis_grad: bool = False,
      test_with_obj: bool = True,
  ) -> None:
      """`Equalization Loss v2 <https://arxiv.org/abs/2012.08548>`_
  
      Args:
          use_sigmoid (bool): EQLv2 uses the sigmoid function to transform
              the predicted logits to an estimated probability distribution.
          reduction (str, optional): The method used to reduce the loss into
              a scalar. Defaults to 'mean'.
          class_weight (Tensor, optional): The weight of loss for each
              prediction. Defaults to None.
          loss_weight (float, optional): The weight of the total EQLv2 loss.
              Defaults to 1.0.
          num_classes (int): 1203 for lvis v1.0, 1230 for lvis v0.5.
          use_distributed (bool, float): EQLv2 will calculate the gradients
              on all GPUs if there is any. Change to True if you are using
              distributed training. Default to False.
          mu (float, optional): Defaults to 0.8
          alpha (float, optional): A balance factor for the negative part of
              EQLV2 Loss. Defaults to 4.0.
          gamma (int, optional): The gamma for calculating the modulating
              factor. Defaults to 12.
          vis_grad (bool, optional): Default to False.
          test_with_obj (bool, optional): Default to True.
  
      Returns:
          None.
      """
      super().__init__()
      self.use_sigmoid = True
      self.reduction = reduction
      self.loss_weight = loss_weight
      self.class_weight = class_weight
      self.num_classes = num_classes
      self.group = True
  
      # cfg for eqlv2
      self.vis_grad = vis_grad
      self.mu = mu
      self.alpha = alpha
      self.gamma = gamma
      self.use_distributed = use_distributed
  
      # initial variables
      self.register_buffer("pos_grad", torch.zeros(self.num_classes))
      self.register_buffer("neg_grad", torch.zeros(self.num_classes))
      # At the beginning of training, we set a high value (eg. 100)
      # for the initial gradient ratio so that the weight for pos
      # gradients and neg gradients are 1.
      self.register_buffer(
          "pos_neg", torch.ones(self.num_classes) * 100
      )
  
      self.test_with_obj = test_with_obj
  
      def _func(x, gamma, mu):
          return 1 / (1 + torch.exp(-gamma * (x - mu)))
  
      self.map_func = partial(_func, gamma=self.gamma, mu=self.mu)
  
      print_log(
          f"build EQL v2, gamma: {gamma}, mu: {mu}, alpha: {alpha}",
          logger="current",
          level=logging.DEBUG,
      )
  
file_path: mmdetection/mmdet/models/losses/eqlv2_loss.py
imports: import logging
  from functools import partial
  from typing import Optional
  import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
  from mmengine.logging import print_log
  from torch import Tensor
  from mmdet.registry import MODELS
label_desc: Use image node_id 1 to create a new EQLV2Loss object from inherited base classes: nn with example: obj = EQLV2Loss(use_sigmoid, reduction, class_weight, loss_weight, num_classes, use_distributed, mu, alpha, gamma, vis_grad, test_with_obj)