class_docstr: Hybrid task cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1901.07518
  
  Args:
      num_stages (int): Number of cascade stages.
      stage_loss_weights (list[float]): Loss weight for every stage.
      semantic_roi_extractor (:obj:`ConfigDict` or dict, optional):
          Config of semantic roi extractor. Defaults to None.
      Semantic_head (:obj:`ConfigDict` or dict, optional):
          Config of semantic head. Defaults to None.
      interleaved (bool): Whether to interleaves the box branch and mask
          branch. If True, the mask branch can take the refined bounding
          box predictions. Defaults to True.
      mask_info_flow (bool): Whether to turn on the mask information flow,
          which means that feeding the mask features of the preceding stage
          to the current stage. Defaults to True.
docstr: Run forward function and calculate loss for mask head in training.
  
  Args:
      stage (int): The current stage in Cascade RoI Head.
      x (tuple[Tensor]): Tuple of multi-level img features.
      sampling_results (list["obj:`SamplingResult`]): Sampling results.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes``, ``labels``, and
          ``masks`` attributes.
      semantic_feat (Tensor, optional): Semantic feature. Defaults to
          None.
  
  Returns:
      dict: Usually returns a dictionary with keys:
  
          - `mask_preds` (Tensor): Mask prediction.
          - `loss_mask` (dict): A dictionary of mask loss components.
docstr_tok: ["Run","forward","function","and","calculate","loss","for","mask","head","in","training",".","Args",":","stage","(","int",")",":","The","current","stage","in","Cascade","RoI","Head",".","x","(","tuple","[","Tensor","]",")",":","Tuple","of","multi-level","img","features",".","sampling_results","(","list","[","``","obj",":","`","SamplingResult","`","]",")",":","Sampling","results",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``",",","``","labels","``",",","and","``","masks","``","attributes",".","semantic_feat","(","Tensor",",","optional",")",":","Semantic","feature",".","Defaults","to","None",".","Returns",":","dict",":","Usually","returns","a","dictionary","with","keys",":","-","`","mask_preds","`","(","Tensor",")",":","Mask","prediction",".","-","`","loss_mask","`","(","dict",")",":","A","dictionary","of","mask","loss","components","."]
code: def mask_loss(
      self,
      stage: int,
      x: Tuple[Tensor],
      sampling_results: List[SamplingResult],
      batch_gt_instances: InstanceList,
      semantic_feat: Optional[Tensor] = None,
  ) -> dict:
      """Run forward function and calculate loss for mask head in training.
  
      Args:
          stage (int): The current stage in Cascade RoI Head.
          x (tuple[Tensor]): Tuple of multi-level img features.
          sampling_results (list["obj:`SamplingResult`]): Sampling results.
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance. It usually includes ``bboxes``, ``labels``, and
              ``masks`` attributes.
          semantic_feat (Tensor, optional): Semantic feature. Defaults to
              None.
  
      Returns:
          dict: Usually returns a dictionary with keys:
  
              - `mask_preds` (Tensor): Mask prediction.
              - `loss_mask` (dict): A dictionary of mask loss components.
      """
      pos_rois = bbox2roi([res.pos_priors for res in sampling_results])
      mask_results = self._mask_forward(
          stage=stage,
          x=x,
          rois=pos_rois,
          semantic_feat=semantic_feat,
          training=True,
      )
  
      mask_head = self.mask_head[stage]
      mask_loss_and_target = 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[stage],
      )
      mask_results.update(mask_loss_and_target)
  
      return mask_results
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import InstanceList, OptConfigType
  from ..layers import adaptive_avg_pool2d
  from ..task_modules.samplers import SamplingResult
  from ..utils import empty_instances, unpack_gt_instances
  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_loss(stage, x, sampling_results, batch_gt_instances, semantic_feat) and returns: mask_results