class_docstr: Hybrid task cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1901.07518
class_docstr_tok: ["Hybrid","task","cascade","roi","head","including","one","bbox","head","and","one","mask","head",".","https",":","\/\/arxiv.org\/abs\/1901.07518"]
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,
      stage,
      x,
      sampling_results,
      gt_masks,
      rcnn_train_cfg,
      semantic_feat=None,
  ):
      """Run forward function and calculate loss for mask head in
      training."""
      mask_roi_extractor = self.mask_roi_extractor[stage]
      mask_head = self.mask_head[stage]
      pos_rois = bbox2roi([res.pos_bboxes for res in sampling_results])
      mask_feats = mask_roi_extractor(
          x[: mask_roi_extractor.num_inputs], pos_rois
      )
  
      # semantic feature fusion
      # element-wise sum for original features and pooled semantic features
      if self.with_semantic and "mask" in self.semantic_fusion:
          mask_semantic_feat = self.semantic_roi_extractor(
              [semantic_feat], pos_rois
          )
          if mask_semantic_feat.shape[-2:] != mask_feats.shape[-2:]:
              mask_semantic_feat = F.adaptive_avg_pool2d(
                  mask_semantic_feat, mask_feats.shape[-2:]
              )
          mask_feats += mask_semantic_feat
  
      # mask information flow
      # forward all previous mask heads to obtain last_feat, and fuse it
      # with the normal mask feature
      if self.mask_info_flow:
          last_feat = None
          for i in range(stage):
              last_feat = self.mask_head[i](
                  mask_feats, last_feat, return_logits=False
              )
          mask_pred = mask_head(
              mask_feats, last_feat, return_feat=False
          )
      else:
          mask_pred = mask_head(mask_feats, return_feat=False)
  
      mask_targets = mask_head.get_targets(
          sampling_results, gt_masks, rcnn_train_cfg
      )
      pos_labels = torch.cat(
          [res.pos_gt_labels for res in sampling_results]
      )
      loss_mask = mask_head.loss(mask_pred, mask_targets, pos_labels)
  
      mask_results = dict(loss_mask=loss_mask)
      return mask_results
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/htc_roi_head.py
imports: import torch
  import torch.nn.functional
  from mmdet.core import bbox2result, bbox2roi, bbox_mapping, merge_aug_bboxes, merge_aug_masks, multiclass_nms
  from ..builder import HEADS, build_head, build_roi_extractor
  from .cascade_roi_head import CascadeRoIHead
label_desc: Use image node_id 6 for calling the HybridTaskCascadeRoIHead obj's underlying member method code with example usage: obj._mask_forward_train(stage, x, sampling_results, gt_masks, rcnn_train_cfg, semantic_feat) and returns: mask_results