class_docstr: CondInst mask head used in https://arxiv.org/abs/1904.02689.
  
  This head outputs the mask for CondInst.
  
  Args:
      mask_feature_head (dict): Config of CondInstMaskFeatHead.
      num_layers (int): Number of dynamic conv layers.
      feat_channels (int): Number of channels in the dynamic conv.
      mask_out_stride (int): The stride of the mask feat.
      size_of_interest (int): The size of the region used in rel coord.
      max_masks_to_train (int): Maximum number of masks to train for
          each image.
      loss_segm (:obj:`ConfigDict` or dict, optional): Config of
          segmentation loss.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config
          of head.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          head.
class_docstr_tok: ["CondInst","mask","head","used","in","https",":","\/\/arxiv.org\/abs\/1904.02689",".","This","head","outputs","the","mask","for","CondInst",".","Args",":","mask_feature_head","(","dict",")",":","Config","of","CondInstMaskFeatHead",".","num_layers","(","int",")",":","Number","of","dynamic","conv","layers",".","feat_channels","(","int",")",":","Number","of","channels","in","the","dynamic","conv",".","mask_out_stride","(","int",")",":","The","stride","of","the","mask","feat",".","size_of_interest","(","int",")",":","The","size","of","the","region","used","in","rel","coord",".","max_masks_to_train","(","int",")",":","Maximum","number","of","masks","to","train","for","each","image",".","loss_segm","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","of","segmentation","loss",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config","of","head",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","head","."]
docstr: Calculate the loss based on the features extracted by the mask head.
  
  Args:
      mask_preds (list[Tensor]): List of predicted masks, each has
          shape (num_classes, H, W).
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes``, ``masks``,
          and ``labels`` attributes.
      batch_img_metas (list[dict]): Meta information of multiple images.
      positive_infos (List[:obj:``InstanceData``]): Information of
          positive samples of each image that are assigned in detection
          head.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Calculate","the","loss","based","on","the","features","extracted","by","the","mask","head",".","Args",":","mask_preds","(","list","[","Tensor","]",")",":","List","of","predicted","masks",",","each","has","shape","(","num_classes",",","H",",","W",")",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``",",","``","masks","``",",","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","multiple","images",".","positive_infos","(","List","[",":","obj",":","``","InstanceData","``","]",")",":","Information","of","positive","samples","of","each","image","that","are","assigned","in","detection","head",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss_by_feat(
      self,
      mask_preds: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      positive_infos: InstanceList,
      **kwargs,
  ) -> dict:
      """Calculate the loss based on the features extracted by the mask head.
  
      Args:
          mask_preds (list[Tensor]): List of predicted masks, each has
              shape (num_classes, H, W).
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance. It usually includes ``bboxes``, ``masks``,
              and ``labels`` attributes.
          batch_img_metas (list[dict]): Meta information of multiple images.
          positive_infos (List[:obj:``InstanceData``]): Information of
              positive samples of each image that are assigned in detection
              head.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      assert (
          positive_infos is not None
      ), "positive_infos should not be None in `CondInstMaskHead`"
      losses = dict()
  
      loss_mask = 0.0
      num_imgs = len(mask_preds)
      total_pos = 0
  
      for idx in range(num_imgs):
          (
              mask_pred,
              pos_mask_targets,
              num_pos,
          ) = self._get_targets_single(
              mask_preds[idx],
              batch_gt_instances[idx],
              positive_infos[idx],
          )
          # mask loss
          total_pos += num_pos
          if num_pos == 0 or pos_mask_targets is None:
              loss = mask_pred.new_zeros(1).mean()
          else:
              loss = self.loss_mask(
                  mask_pred, pos_mask_targets, reduction_override="none"
              ).sum()
          loss_mask += loss
  
      if total_pos == 0:
          total_pos += 1  # avoid nan
      loss_mask = loss_mask / total_pos
      losses.update(loss_mask=loss_mask)
      return losses
  
imports: import copy
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, kaiming_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import MlvlPointGenerator
  from ..utils import aligned_bilinear, filter_scores_and_topk, multi_apply, relative_coordinate_maps, select_single_mlvl
  from ..utils.misc import empty_instances
  from .base_mask_head import BaseMaskHead
  from .fcos_head import FCOSHead
label_desc: Use image node_id 7 for calling the CondInstMaskHead obj's underlying member method code with example usage: obj.loss_by_feat(mask_preds, batch_gt_instances, batch_img_metas, positive_infos) and returns: losses