class_docstr: Simplest base roi head including one bbox head and one mask head.
class_docstr_tok: ["Simplest","base","roi","head","including","one","bbox","head","and","one","mask","head","."]
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."""
      if not self.share_roi_extractor:
          pos_rois = bbox2roi(
              [res.pos_bboxes for res in sampling_results]
          )
          mask_results = self._mask_forward(x, pos_rois)
      else:
          pos_inds = []
          device = bbox_feats.device
          for res in sampling_results:
              pos_inds.append(
                  torch.ones(
                      res.pos_bboxes.shape[0],
                      device=device,
                      dtype=torch.uint8,
                  )
              )
              pos_inds.append(
                  torch.zeros(
                      res.neg_bboxes.shape[0],
                      device=device,
                      dtype=torch.uint8,
                  )
              )
          pos_inds = torch.cat(pos_inds)
  
          mask_results = self._mask_forward(
              x, pos_inds=pos_inds, bbox_feats=bbox_feats
          )
  
      mask_targets = self.mask_head.get_targets(
          sampling_results, gt_masks, self.train_cfg
      )
      pos_labels = torch.cat(
          [res.pos_gt_labels for res in sampling_results]
      )
      loss_mask = self.mask_head.loss(
          mask_results["mask_pred"], mask_targets, pos_labels
      )
  
      mask_results.update(
          loss_mask=loss_mask, mask_targets=mask_targets
      )
      return mask_results
  
imports: import torch
  from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
  from ..builder import HEADS, build_head, build_roi_extractor
  from .base_roi_head import BaseRoIHead
  from .test_mixins import BBoxTestMixin, MaskTestMixin
label_desc: Use image node_id 9 for calling the StandardRoIHead 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