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 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 probability 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","probability","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: Tensor, matched_box_prob: Tensor
  ) -> Tensor:
      """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 probability 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: 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 4 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