class_docstr: The RoI head for `Prime Sample Attention in Object Detection
  <https://arxiv.org/abs/1904.04821>`_.
docstr: Forward function for training.
  
  Args:
      x (list[Tensor]): List of multi-level img features.
      img_metas (list[dict]): List of image info dict where each dict
          has: 'img_shape', 'scale_factor', 'flip', and may also contain
          'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
          For details on the values of these keys see
          `mmdet/datasets/pipelines/formatting.py:Collect`.
      proposals (list[Tensors]): List of region proposals.
      gt_bboxes (list[Tensor]): Each item are the truth boxes for each
          image in [tl_x, tl_y, br_x, br_y] format.
      gt_labels (list[Tensor]): Class indices corresponding to each box
      gt_bboxes_ignore (list[Tensor], optional): Specify which bounding
          boxes can be ignored when computing the loss.
      gt_masks (None | Tensor) : True segmentation masks for each box
          used if the architecture supports a segmentation task.
  
  Returns:
      dict[str, Tensor]: a dictionary of loss components
docstr_tok: ["Forward","function","for","training",".","Args",":","x","(","list","[","Tensor","]",")",":","List","of","multi-level","img","features",".","img_metas","(","list","[","dict","]",")",":","List","of","image","info","dict","where","each","dict","has",":","'img_shape","'",",","'scale_factor","'",",","'flip","'",",","and","may","also","contain","'filename","'",",","'ori_shape","'",",","'pad_shape","'",",","and","'img_norm_cfg","'",".","For","details","on","the","values","of","these","keys","see","`","mmdet\/datasets\/pipelines\/formatting.py",":","Collect","`",".","proposals","(","list","[","Tensors","]",")",":","List","of","region","proposals",".","gt_bboxes","(","list","[","Tensor","]",")",":","Each","item","are","the","truth","boxes","for","each","image","in","[","tl_x",",","tl_y",",","br_x",",","br_y","]","format",".","gt_labels","(","list","[","Tensor","]",")",":","Class","indices","corresponding","to","each","box","gt_bboxes_ignore","(","list","[","Tensor","]",",","optional",")",":","Specify","which","bounding","boxes","can","be","ignored","when","computing","the","loss",".","gt_masks","(","None","|","Tensor",")",":","True","segmentation","masks","for","each","box","used","if","the","architecture","supports","a","segmentation","task",".","Returns",":","dict","[","str",",","Tensor","]",":","a","dictionary","of","loss","components"]
code: def forward_train(
      self,
      x,
      img_metas,
      proposal_list,
      gt_bboxes,
      gt_labels,
      gt_bboxes_ignore=None,
      gt_masks=None,
  ):
      """Forward function for training.
  
      Args:
          x (list[Tensor]): List of multi-level img features.
          img_metas (list[dict]): List of image info dict where each dict
              has: 'img_shape', 'scale_factor', 'flip', and may also contain
              'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
              For details on the values of these keys see
              `mmdet/datasets/pipelines/formatting.py:Collect`.
          proposals (list[Tensors]): List of region proposals.
          gt_bboxes (list[Tensor]): Each item are the truth boxes for each
              image in [tl_x, tl_y, br_x, br_y] format.
          gt_labels (list[Tensor]): Class indices corresponding to each box
          gt_bboxes_ignore (list[Tensor], optional): Specify which bounding
              boxes can be ignored when computing the loss.
          gt_masks (None | Tensor) : True segmentation masks for each box
              used if the architecture supports a segmentation task.
  
      Returns:
          dict[str, Tensor]: a dictionary of loss components
      """
      # assign gts and sample proposals
      if self.with_bbox or self.with_mask:
          num_imgs = len(img_metas)
          if gt_bboxes_ignore is None:
              gt_bboxes_ignore = [None for _ in range(num_imgs)]
          sampling_results = []
          neg_label_weights = []
          for i in range(num_imgs):
              assign_result = self.bbox_assigner.assign(
                  proposal_list[i],
                  gt_bboxes[i],
                  gt_bboxes_ignore[i],
                  gt_labels[i],
              )
              sampling_result = self.bbox_sampler.sample(
                  assign_result,
                  proposal_list[i],
                  gt_bboxes[i],
                  gt_labels[i],
                  feats=[lvl_feat[i][None] for lvl_feat in x],
              )
              # neg label weight is obtained by sampling when using ISR-N
              neg_label_weight = None
              if isinstance(sampling_result, tuple):
                  sampling_result, neg_label_weight = sampling_result
              sampling_results.append(sampling_result)
              neg_label_weights.append(neg_label_weight)
  
      losses = dict()
      # bbox head forward and loss
      if self.with_bbox:
          bbox_results = self._bbox_forward_train(
              x,
              sampling_results,
              gt_bboxes,
              gt_labels,
              img_metas,
              neg_label_weights=neg_label_weights,
          )
          losses.update(bbox_results["loss_bbox"])
  
      # mask head forward and loss
      if self.with_mask:
          mask_results = self._mask_forward_train(
              x,
              sampling_results,
              bbox_results["bbox_feats"],
              gt_masks,
              img_metas,
          )
          losses.update(mask_results["loss_mask"])
  
      return losses
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/pisa_roi_head.py
imports: from mmdet.core import bbox2roi
  from ..builder import HEADS
  from ..losses.pisa_loss import carl_loss, isr_p
  from .standard_roi_head import StandardRoIHead
label_desc: Use image node_id 1 for calling the PISARoIHead obj's underlying member method code with example usage: obj.forward_train(x, img_metas, proposal_list, gt_bboxes, gt_labels, gt_bboxes_ignore, gt_masks) and returns: losses