class_docstr: Simplest base roi head including one bbox head and one mask head.
docstr: Mask head forward function used in both training and testing.
  
  Args:
      x (tuple[Tensor]): Tuple of multi-level img features.
      rois (Tensor): RoIs with the shape (n, 5) where the first
          column indicates batch id of each RoI.
      pos_inds (Tensor, optional): Indices of positive samples.
          Defaults to None.
      bbox_feats (Tensor): Extract bbox RoI features. Defaults to None.
  
  Returns:
      dict[str, Tensor]: Usually returns a dictionary with keys:
  
          - `mask_preds` (Tensor): Mask prediction.
          - `mask_feats` (Tensor): Extract mask RoI features.
docstr_tok: ["Mask","head","forward","function","used","in","both","training","and","testing",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Tuple","of","multi-level","img","features",".","rois","(","Tensor",")",":","RoIs","with","the","shape","(","n",",","5",")","where","the","first","column","indicates","batch","id","of","each","RoI",".","pos_inds","(","Tensor",",","optional",")",":","Indices","of","positive","samples",".","Defaults","to","None",".","bbox_feats","(","Tensor",")",":","Extract","bbox","RoI","features",".","Defaults","to","None",".","Returns",":","dict","[","str",",","Tensor","]",":","Usually","returns","a","dictionary","with","keys",":","-","`","mask_preds","`","(","Tensor",")",":","Mask","prediction",".","-","`","mask_feats","`","(","Tensor",")",":","Extract","mask","RoI","features","."]
code: def _mask_forward(
      self,
      x: Tuple[Tensor],
      rois: Tensor = None,
      pos_inds: Optional[Tensor] = None,
      bbox_feats: Optional[Tensor] = None,
  ) -> dict:
      """Mask head forward function used in both training and testing.
  
      Args:
          x (tuple[Tensor]): Tuple of multi-level img features.
          rois (Tensor): RoIs with the shape (n, 5) where the first
              column indicates batch id of each RoI.
          pos_inds (Tensor, optional): Indices of positive samples.
              Defaults to None.
          bbox_feats (Tensor): Extract bbox RoI features. Defaults to None.
  
      Returns:
          dict[str, Tensor]: Usually returns a dictionary with keys:
  
              - `mask_preds` (Tensor): Mask prediction.
              - `mask_feats` (Tensor): Extract mask RoI features.
      """
      assert (rois is not None) ^ (
          pos_inds is not None and bbox_feats is not None
      )
      if rois is not None:
          mask_feats = self.mask_roi_extractor(
              x[: self.mask_roi_extractor.num_inputs], rois
          )
          if self.with_shared_head:
              mask_feats = self.shared_head(mask_feats)
      else:
          assert bbox_feats is not None
          mask_feats = bbox_feats[pos_inds]
  
      mask_preds = self.mask_head(mask_feats)
      mask_results = dict(mask_preds=mask_preds, mask_feats=mask_feats)
      return mask_results
  
imports: from typing import List, Optional, Tuple
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import DetDataSample, SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import ConfigType, InstanceList
  from ..task_modules.samplers import SamplingResult
  from ..utils import empty_instances, unpack_gt_instances
  from .base_roi_head import BaseRoIHead
label_desc: Use image node_id 9 for calling the StandardRoIHead obj's underlying member method code with example usage: obj._mask_forward(x, rois, pos_inds, bbox_feats) and returns: mask_results