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.
          Default: 4.
      conv_cfg (dict): dictionary to construct and config conv layer.
          Default: None.
      norm_cfg (dict): dictionary to construct and config norm layer.
          Default: norm_cfg=dict(type='GN', num_groups=32,
          requires_grad=True).
      pre_anchor_topk (int): Number of boxes that be token in each bag.
      bbox_thr (float): The threshold of the saturated linear function. It is
          usually the same with the IoU threshold used in NMS.
      gamma (float): Gamma parameter in focal loss.
      alpha (float): Alpha parameter in focal loss.
docstr: Compute positive bag loss.
  
  :math:`-log( Mean-max(P_{ij}^{cls} * P_{ij}^{loc}) )`.
  
  :math:`P_{ij}^{cls}`: matched_cls_prob, classification probability of matched samples.
  
  :math:`P_{ij}^{loc}`: matched_box_prob, box probability of matched samples.
  
  Args:
      matched_cls_prob (Tensor): Classification probabilty of matched
          samples in shape (num_gt, pre_anchor_topk).
      matched_box_prob (Tensor): BBox probability of matched samples,
          in shape (num_gt, pre_anchor_topk).
  
  Returns:
      Tensor: Positive bag loss in shape (num_gt,).
docstr_tok: ["Compute","positive","bag","loss",".",":","math",":","`","-log","(","Mean-max","(","P_","{","ij","}","^","{","cls","}","*","P_","{","ij","}","^","{","loc","}",")",")","`",".",":","math",":","`","P_","{","ij","}","^","{","cls","}","`",":","matched_cls_prob",",","classification","probability","of","matched","samples",".",":","math",":","`","P_","{","ij","}","^","{","loc","}","`",":","matched_box_prob",",","box","probability","of","matched","samples",".","Args",":","matched_cls_prob","(","Tensor",")",":","Classification","probabilty","of","matched","samples","in","shape","(","num_gt",",","pre_anchor_topk",")",".","matched_box_prob","(","Tensor",")",":","BBox","probability","of","matched","samples",",","in","shape","(","num_gt",",","pre_anchor_topk",")",".","Returns",":","Tensor",":","Positive","bag","loss","in","shape","(","num_gt",",",")","."]
code: def positive_bag_loss(self, matched_cls_prob, matched_box_prob):
      """Compute positive bag loss.
  
      :math:`-log( Mean-max(P_{ij}^{cls} * P_{ij}^{loc}) )`.
  
      :math:`P_{ij}^{cls}`: matched_cls_prob, classification probability of matched samples.
  
      :math:`P_{ij}^{loc}`: matched_box_prob, box probability of matched samples.
  
      Args:
          matched_cls_prob (Tensor): Classification probabilty of matched
              samples in shape (num_gt, pre_anchor_topk).
          matched_box_prob (Tensor): BBox probability of matched samples,
              in shape (num_gt, pre_anchor_topk).
  
      Returns:
          Tensor: Positive bag loss in shape (num_gt,).
      """  # noqa: E501, W605
      # bag_prob = Mean-max(matched_prob)
      matched_prob = matched_cls_prob * matched_box_prob
      weight = 1 / torch.clamp(1 - matched_prob, 1e-12, None)
      weight /= weight.sum(dim=1).unsqueeze(dim=-1)
      bag_prob = (weight * matched_prob).sum(dim=1)
      # positive_bag_loss = -self.alpha * log(bag_prob)
      return self.alpha * F.binary_cross_entropy(
          bag_prob, torch.ones_like(bag_prob), reduction="none"
      )
  
file_path: insightface/detection/scrfd/mmdet/models/dense_heads/free_anchor_retina_head.py
imports: import torch
  import torch.nn.functional
  from mmdet.core import bbox_overlaps
  from ..builder import HEADS
  from .retina_head import RetinaHead
label_desc: Use image node_id 3 for calling the FreeAnchorRetinaHead obj's underlying member method code with example usage: obj.positive_bag_loss(matched_cls_prob, matched_box_prob) and returns: unknown