class_docstr: FreeAnchor RetinaHead used in https://arxiv.org/abs/1909.02466.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      stacked_convs (int): Number of conv layers in cls and reg tower.
          Defaults to 4.
      conv_cfg (:obj:`ConfigDict` or dict, optional): dictionary to
          construct and config conv layer. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict, optional): dictionary to
          construct and config norm layer. Defaults to
          norm_cfg=dict(type='GN', num_groups=32, requires_grad=True).
      pre_anchor_topk (int): Number of boxes that be token in each bag.
          Defaults to 50
      bbox_thr (float): The threshold of the saturated linear function.
          It is usually the same with the IoU threshold used in NMS.
          Defaults to 0.6.
      gamma (float): Gamma parameter in focal loss. Defaults to 2.0.
      alpha (float): Alpha parameter in focal loss. Defaults to 0.5.
class_docstr_tok: ["FreeAnchor","RetinaHead","used","in","https",":","\/\/arxiv.org\/abs\/1909.02466",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","stacked_convs","(","int",")",":","Number","of","conv","layers","in","cls","and","reg","tower",".","Defaults","to","4.","conv_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","dictionary","to","construct","and","config","conv","layer",".","Defaults","to","None",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","dictionary","to","construct","and","config","norm","layer",".","Defaults","to","norm_cfg=dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","pre_anchor_topk","(","int",")",":","Number","of","boxes","that","be","token","in","each","bag",".","Defaults","to","50","bbox_thr","(","float",")",":","The","threshold","of","the","saturated","linear","function",".","It","is","usually","the","same","with","the","IoU","threshold","used","in","NMS",".","Defaults","to","0.6.","gamma","(","float",")",":","Gamma","parameter","in","focal","loss",".","Defaults","to","2.0.","alpha","(","float",")",":","Alpha","parameter","in","focal","loss",".","Defaults","to","0.5","."]
docstr: Compute negative bag loss.
  
  :math:`FL((1 - P_{a_{j} \in A_{+}}) * (1 - P_{j}^{bg}))`.
  
  :math:`P_{a_{j} \in A_{+}}`: Box_probability of matched samples.
  
  :math:`P_{j}^{bg}`: Classification probability of negative samples.
  
  Args:
      cls_prob (Tensor): Classification probability, in shape
          (num_img, num_anchors, num_classes).
      box_prob (Tensor): Box probability, in shape
          (num_img, num_anchors, num_classes).
  
  Returns:
      Tensor: Negative bag loss in shape (num_img, num_anchors,
      num_classes).
docstr_tok: ["Compute","negative","bag","loss",".",":","math",":","`","FL","(","(","1","-","P_","{","a_","{","j","}","\\in","A_","{","+","}","}",")","*","(","1","-","P_","{","j","}","^","{","bg","}",")",")","`",".",":","math",":","`","P_","{","a_","{","j","}","\\in","A_","{","+","}","}","`",":","Box_probability","of","matched","samples",".",":","math",":","`","P_","{","j","}","^","{","bg","}","`",":","Classification","probability","of","negative","samples",".","Args",":","cls_prob","(","Tensor",")",":","Classification","probability",",","in","shape","(","num_img",",","num_anchors",",","num_classes",")",".","box_prob","(","Tensor",")",":","Box","probability",",","in","shape","(","num_img",",","num_anchors",",","num_classes",")",".","Returns",":","Tensor",":","Negative","bag","loss","in","shape","(","num_img",",","num_anchors",",","num_classes",")","."]
code: def negative_bag_loss(
      self, cls_prob: Tensor, box_prob: Tensor
  ) -> Tensor:
      """Compute negative bag loss.
  
      :math:`FL((1 - P_{a_{j} \in A_{+}}) * (1 - P_{j}^{bg}))`.
  
      :math:`P_{a_{j} \in A_{+}}`: Box_probability of matched samples.
  
      :math:`P_{j}^{bg}`: Classification probability of negative samples.
  
      Args:
          cls_prob (Tensor): Classification probability, in shape
              (num_img, num_anchors, num_classes).
          box_prob (Tensor): Box probability, in shape
              (num_img, num_anchors, num_classes).
  
      Returns:
          Tensor: Negative bag loss in shape (num_img, num_anchors,
          num_classes).
      """  # noqa: E501, W605
      prob = cls_prob * (1 - box_prob)
      # There are some cases when neg_prob = 0.
      # This will cause the neg_prob.log() to be inf without clamp.
      prob = prob.clamp(min=EPS, max=1 - EPS)
      negative_bag_loss = prob**self.gamma * F.binary_cross_entropy(
          prob, torch.zeros_like(prob), reduction="none"
      )
      return (1 - self.alpha) * negative_bag_loss
  
file_path: mmdetection/mmdet/models/dense_heads/free_anchor_retina_head.py
imports: from typing import List
  import torch
  import torch.nn.functional
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import InstanceList, OptConfigType, OptInstanceList
  from ..utils import multi_apply
  from .retina_head import RetinaHead
label_desc: Use image node_id 5 for calling the FreeAnchorRetinaHead obj's underlying member method code with example usage: obj.negative_bag_loss(cls_prob, box_prob) and returns: unknown