class_docstr: Mask Scoring RoIHead for Mask Scoring RCNN.
  
  https://arxiv.org/abs/1903.00241
docstr: Run forward function and calculate loss for Mask head in
  training.
docstr_tok: ["Run","forward","function","and","calculate","loss","for","Mask","head","in","training","."]
code: def _mask_forward_train(
      self, x, sampling_results, bbox_feats, gt_masks, img_metas
  ):
      """Run forward function and calculate loss for Mask head in
      training."""
      pos_labels = torch.cat(
          [res.pos_gt_labels for res in sampling_results]
      )
      mask_results = super(
          MaskScoringRoIHead, self
      )._mask_forward_train(
          x, sampling_results, bbox_feats, gt_masks, img_metas
      )
      if mask_results["loss_mask"] is None:
          return mask_results
  
      # mask iou head forward and loss
      pos_mask_pred = mask_results["mask_pred"][
          range(mask_results["mask_pred"].size(0)), pos_labels
      ]
      mask_iou_pred = self.mask_iou_head(
          mask_results["mask_feats"], pos_mask_pred
      )
      pos_mask_iou_pred = mask_iou_pred[
          range(mask_iou_pred.size(0)), pos_labels
      ]
  
      mask_iou_targets = self.mask_iou_head.get_targets(
          sampling_results,
          gt_masks,
          pos_mask_pred,
          mask_results["mask_targets"],
          self.train_cfg,
      )
      loss_mask_iou = self.mask_iou_head.loss(
          pos_mask_iou_pred, mask_iou_targets
      )
      mask_results["loss_mask"].update(loss_mask_iou)
      return mask_results
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/mask_scoring_roi_head.py
imports: import torch
  from mmdet.core import bbox2roi
  from ..builder import HEADS, build_head
  from .standard_roi_head import StandardRoIHead
label_desc: Use image node_id 3 for calling the MaskScoringRoIHead obj's underlying member method code with example usage: obj._mask_forward_train(x, sampling_results, bbox_feats, gt_masks, img_metas) and returns: mask_results, mask_results