class_docstr: Simplest base roi head including one bbox head and one mask head.
docstr: Perform forward propagation and loss calculation of the mask head on
  the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): Tuple of multi-level img features.
      sampling_results (list["obj:`SamplingResult`]): Sampling results.
      bbox_feats (Tensor): Extract bbox RoI features.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes``, ``labels``, and
          ``masks`` attributes.
  
  Returns:
      dict: Usually returns a dictionary with keys:
  
          - `mask_preds` (Tensor): Mask prediction.
          - `mask_feats` (Tensor): Extract mask RoI features.
          - `mask_targets` (Tensor): Mask target of each positive                    proposals in the image.
          - `loss_mask` (dict): A dictionary of mask loss components.
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","mask","head","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Tuple","of","multi-level","img","features",".","sampling_results","(","list","[","``","obj",":","`","SamplingResult","`","]",")",":","Sampling","results",".","bbox_feats","(","Tensor",")",":","Extract","bbox","RoI","features",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``",",","``","labels","``",",","and","``","masks","``","attributes",".","Returns",":","dict",":","Usually","returns","a","dictionary","with","keys",":","-","`","mask_preds","`","(","Tensor",")",":","Mask","prediction",".","-","`","mask_feats","`","(","Tensor",")",":","Extract","mask","RoI","features",".","-","`","mask_targets","`","(","Tensor",")",":","Mask","target","of","each","positive","proposals","in","the","image",".","-","`","loss_mask","`","(","dict",")",":","A","dictionary","of","mask","loss","components","."]
code: def mask_loss(
      self,
      x: Tuple[Tensor],
      sampling_results: List[SamplingResult],
      bbox_feats: Tensor,
      batch_gt_instances: InstanceList,
  ) -> dict:
      """Perform forward propagation and loss calculation of the mask head on
          the features of the upstream network.
  
          Args:
              x (tuple[Tensor]): Tuple of multi-level img features.
              sampling_results (list["obj:`SamplingResult`]): Sampling results.
              bbox_feats (Tensor): Extract bbox RoI features.
              batch_gt_instances (list[:obj:`InstanceData`]): Batch of
                  gt_instance. It usually includes ``bboxes``, ``labels``, and
                  ``masks`` attributes.
  
          Returns:
              dict: Usually returns a dictionary with keys:
  
                  - `mask_preds` (Tensor): Mask prediction.
                  - `mask_feats` (Tensor): Extract mask RoI features.
                  - `mask_targets` (Tensor): Mask target of each positive\
                      proposals in the image.
                  - `loss_mask` (dict): A dictionary of mask loss components.
          """
      if not self.share_roi_extractor:
          pos_rois = bbox2roi(
              [res.pos_priors 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_priors.shape[0],
                      device=device,
                      dtype=torch.uint8,
                  )
              )
              pos_inds.append(
                  torch.zeros(
                      res.neg_priors.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_loss_and_target = self.mask_head.loss_and_target(
          mask_preds=mask_results["mask_preds"],
          sampling_results=sampling_results,
          batch_gt_instances=batch_gt_instances,
          rcnn_train_cfg=self.train_cfg,
      )
  
      mask_results.update(loss_mask=mask_loss_and_target["loss_mask"])
      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 8 for calling the StandardRoIHead obj's underlying member method code with example usage: obj.mask_loss(x, sampling_results, bbox_feats, batch_gt_instances) and returns: mask_results