class_docstr: Base class for mask heads used in One-Stage Instance Segmentation.
class_docstr_tok: ["Base","class","for","mask","heads","used","in","One-Stage","Instance","Segmentation","."]
docstr: Perform forward propagation and loss calculation of the mask head on
  the features of the upstream network.
  
  Args:
      x (list[Tensor] | tuple[Tensor]): Features from FPN.
          Each has a shape (B, C, H, W).
      batch_data_samples (list[:obj:`DetDataSample`]): Each item contains
          the meta information of each image and corresponding
          annotations.
      positive_infos (list[:obj:`InstanceData`], optional): Information
          of positive samples. Used when the label assignment is
          done outside the MaskHead, e.g., BboxHead in
          YOLACT or CondInst, etc. When the label assignment is done in
          MaskHead, it would be None, like SOLO or SOLOv2. All values
          in it should have shape (num_positive_samples, *).
  
  
  Returns:
      dict: A dictionary of loss components.
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","mask","head","on","the","features","of","the","upstream","network",".","Args",":","x","(","list","[","Tensor","]","|","tuple","[","Tensor","]",")",":","Features","from","FPN",".","Each","has","a","shape","(","B",",","C",",","H",",","W",")",".","batch_data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]",")",":","Each","item","contains","the","meta","information","of","each","image","and","corresponding","annotations",".","positive_infos","(","list","[",":","obj",":","`","InstanceData","`","]",",","optional",")",":","Information","of","positive","samples",".","Used","when","the","label","assignment","is","done","outside","the","MaskHead",",","e.g.",",","BboxHead","in","YOLACT","or","CondInst",",","etc",".","When","the","label","assignment","is","done","in","MaskHead",",","it","would","be","None",",","like","SOLO","or","SOLOv2",".","All","values","in","it","should","have","shape","(","num_positive_samples",",","*",")",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss(
      self,
      x: Union[List[Tensor], Tuple[Tensor]],
      batch_data_samples: SampleList,
      positive_infos: OptInstanceList = None,
      **kwargs,
  ) -> dict:
      """Perform forward propagation and loss calculation of the mask head on
      the features of the upstream network.
  
      Args:
          x (list[Tensor] | tuple[Tensor]): Features from FPN.
              Each has a shape (B, C, H, W).
          batch_data_samples (list[:obj:`DetDataSample`]): Each item contains
              the meta information of each image and corresponding
              annotations.
          positive_infos (list[:obj:`InstanceData`], optional): Information
              of positive samples. Used when the label assignment is
              done outside the MaskHead, e.g., BboxHead in
              YOLACT or CondInst, etc. When the label assignment is done in
              MaskHead, it would be None, like SOLO or SOLOv2. All values
              in it should have shape (num_positive_samples, *).
  
  
      Returns:
          dict: A dictionary of loss components.
      """
      if positive_infos is None:
          outs = self(x)
      else:
          outs = self(x, positive_infos)
  
      assert isinstance(outs, tuple), (
          "Forward results should be a tuple, "
          "even if only one item is returned"
      )
  
      outputs = unpack_gt_instances(batch_data_samples)
      (
          batch_gt_instances,
          batch_gt_instances_ignore,
          batch_img_metas,
      ) = outputs
      for gt_instances, img_metas in zip(
          batch_gt_instances, batch_img_metas
      ):
          img_shape = img_metas["batch_input_shape"]
          gt_masks = gt_instances.masks.pad(img_shape)
          gt_instances.masks = gt_masks
  
      losses = self.loss_by_feat(
          *outs,
          batch_gt_instances=batch_gt_instances,
          batch_img_metas=batch_img_metas,
          positive_infos=positive_infos,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
          **kwargs,
      )
      return losses
  
file_path: mmdetection/mmdet/models/dense_heads/base_mask_head.py
imports: from abc import ABCMeta, abstractmethod
  from typing import List, Tuple, Union
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.structures import SampleList
  from mmdet.utils import InstanceList, OptInstanceList, OptMultiConfig
  from ..utils import unpack_gt_instances
label_desc: Use image node_id 4 for calling the BaseMaskHead obj's underlying member method code with example usage: obj.loss(x, batch_data_samples, positive_infos) and returns: losses