class_docstr: SOLOv2 mask head used in `SOLOv2: Dynamic and Fast Instance
  Segmentation. <https://arxiv.org/pdf/2003.10152>`_
  
  Args:
      mask_feature_head (dict): Config of SOLOv2MaskFeatHead.
      dynamic_conv_size (int): Dynamic Conv kernel size. Defaults to 1.
      dcn_cfg (dict): Dcn conv configurations in kernel_convs and cls_conv.
          Defaults to None.
      dcn_apply_to_all_conv (bool): Whether to use dcn in every layer of
          kernel_convs and cls_convs, or only the last layer. It shall be set
          `True` for the normal version of SOLOv2 and `False` for the
          light-weight version. Defaults to True.
      init_cfg (dict or list[dict], optional): Initialization config dict.
class_docstr_tok: ["SOLOv2","mask","head","used","in","`","SOLOv2",":","Dynamic","and","Fast","Instance","Segmentation",".","<","https",":","\/\/arxiv.org\/pdf\/2003.10152",">","`","_","Args",":","mask_feature_head","(","dict",")",":","Config","of","SOLOv2MaskFeatHead",".","dynamic_conv_size","(","int",")",":","Dynamic","Conv","kernel","size",".","Defaults","to","1.","dcn_cfg","(","dict",")",":","Dcn","conv","configurations","in","kernel_convs","and","cls_conv",".","Defaults","to","None",".","dcn_apply_to_all_conv","(","bool",")",":","Whether","to","use","dcn","in","every","layer","of","kernel_convs","and","cls_convs",",","or","only","the","last","layer",".","It","shall","be","set","`","True","`","for","the","normal","version","of","SOLOv2","and","`","False","`","for","the","light-weight","version",".","Defaults","to","True",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Transform a single image's features extracted from the head into
  mask results.
  
  Args:
      kernel_preds (Tensor): Dynamic kernel prediction of all points
          in single image, has shape
          (num_points, kernel_out_channels).
      cls_scores (Tensor): Classification score of all points
          in single image, has shape (num_points, num_classes).
      mask_feats (Tensor): Mask prediction of all points in
          single image, has shape (num_points, feat_h, feat_w).
      img_meta (dict): Meta information of corresponding image.
      cfg (dict, optional): Config used in test phase.
          Defaults to None.
  
  Returns:
      :obj:`InstanceData`: Processed results of single image.
       it usually contains following keys.
  
          - scores (Tensor): Classification scores, has shape
            (num_instance,).
          - labels (Tensor): Has shape (num_instances,).
          - masks (Tensor): Processed mask results, has
            shape (num_instances, h, w).
docstr_tok: ["Transform","a","single","image","'s","features","extracted","from","the","head","into","mask","results",".","Args",":","kernel_preds","(","Tensor",")",":","Dynamic","kernel","prediction","of","all","points","in","single","image",",","has","shape","(","num_points",",","kernel_out_channels",")",".","cls_scores","(","Tensor",")",":","Classification","score","of","all","points","in","single","image",",","has","shape","(","num_points",",","num_classes",")",".","mask_feats","(","Tensor",")",":","Mask","prediction","of","all","points","in","single","image",",","has","shape","(","num_points",",","feat_h",",","feat_w",")",".","img_meta","(","dict",")",":","Meta","information","of","corresponding","image",".","cfg","(","dict",",","optional",")",":","Config","used","in","test","phase",".","Defaults","to","None",".","Returns",":",":","obj",":","`","InstanceData","`",":","Processed","results","of","single","image",".","it","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","shape","(","num_instance",",",")",".","-","labels","(","Tensor",")",":","Has","shape","(","num_instances",",",")",".","-","masks","(","Tensor",")",":","Processed","mask","results",",","has","shape","(","num_instances",",","h",",","w",")","."]
code: def _predict_by_feat_single(
      self,
      kernel_preds: Tensor,
      cls_scores: Tensor,
      mask_feats: Tensor,
      img_meta: dict,
      cfg: OptConfigType = None,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      mask results.
  
      Args:
          kernel_preds (Tensor): Dynamic kernel prediction of all points
              in single image, has shape
              (num_points, kernel_out_channels).
          cls_scores (Tensor): Classification score of all points
              in single image, has shape (num_points, num_classes).
          mask_feats (Tensor): Mask prediction of all points in
              single image, has shape (num_points, feat_h, feat_w).
          img_meta (dict): Meta information of corresponding image.
          cfg (dict, optional): Config used in test phase.
              Defaults to None.
  
      Returns:
          :obj:`InstanceData`: Processed results of single image.
           it usually contains following keys.
  
              - scores (Tensor): Classification scores, has shape
                (num_instance,).
              - labels (Tensor): Has shape (num_instances,).
              - masks (Tensor): Processed mask results, has
                shape (num_instances, h, w).
      """
  
      def empty_results(cls_scores, ori_shape):
          """Generate a empty results."""
          results = InstanceData()
          results.scores = cls_scores.new_ones(0)
          results.masks = cls_scores.new_zeros(0, *ori_shape)
          results.labels = cls_scores.new_ones(0)
          results.bboxes = cls_scores.new_zeros(0, 4)
          return results
  
      cfg = self.test_cfg if cfg is None else cfg
      assert len(kernel_preds) == len(cls_scores)
  
      featmap_size = mask_feats.size()[-2:]
  
      # overall info
      h, w = img_meta["img_shape"][:2]
      upsampled_size = (
          featmap_size[0] * self.mask_stride,
          featmap_size[1] * self.mask_stride,
      )
  
      # process.
      score_mask = cls_scores > cfg.score_thr
      cls_scores = cls_scores[score_mask]
      if len(cls_scores) == 0:
          return empty_results(cls_scores, img_meta["ori_shape"][:2])
  
      # cate_labels & kernel_preds
      inds = score_mask.nonzero()
      cls_labels = inds[:, 1]
      kernel_preds = kernel_preds[inds[:, 0]]
  
      # trans vector.
      lvl_interval = (
          cls_labels.new_tensor(self.num_grids).pow(2).cumsum(0)
      )
      strides = kernel_preds.new_ones(lvl_interval[-1])
  
      strides[: lvl_interval[0]] *= self.strides[0]
      for lvl in range(1, self.num_levels):
          strides[
              lvl_interval[lvl - 1] : lvl_interval[lvl]
          ] *= self.strides[lvl]
      strides = strides[inds[:, 0]]
  
      # mask encoding.
      kernel_preds = kernel_preds.view(
          kernel_preds.size(0),
          -1,
          self.dynamic_conv_size,
          self.dynamic_conv_size,
      )
      mask_preds = (
          F.conv2d(mask_feats, kernel_preds, stride=1)
          .squeeze(0)
          .sigmoid()
      )
      # mask.
      masks = mask_preds > cfg.mask_thr
      sum_masks = masks.sum((1, 2)).float()
      keep = sum_masks > strides
      if keep.sum() == 0:
          return empty_results(cls_scores, img_meta["ori_shape"][:2])
      masks = masks[keep]
      mask_preds = mask_preds[keep]
      sum_masks = sum_masks[keep]
      cls_scores = cls_scores[keep]
      cls_labels = cls_labels[keep]
  
      # maskness.
      mask_scores = (mask_preds * masks).sum((1, 2)) / sum_masks
      cls_scores *= mask_scores
  
      scores, labels, _, keep_inds = mask_matrix_nms(
          masks,
          cls_labels,
          cls_scores,
          mask_area=sum_masks,
          nms_pre=cfg.nms_pre,
          max_num=cfg.max_per_img,
          kernel=cfg.kernel,
          sigma=cfg.sigma,
          filter_thr=cfg.filter_thr,
      )
      if len(keep_inds) == 0:
          return empty_results(cls_scores, img_meta["ori_shape"][:2])
      mask_preds = mask_preds[keep_inds]
      mask_preds = F.interpolate(
          mask_preds.unsqueeze(0),
          size=upsampled_size,
          mode="bilinear",
          align_corners=False,
      )[:, :, :h, :w]
      mask_preds = F.interpolate(
          mask_preds,
          size=img_meta["ori_shape"][:2],
          mode="bilinear",
          align_corners=False,
      ).squeeze(0)
      masks = mask_preds > cfg.mask_thr
  
      results = InstanceData()
      results.masks = masks
      results.labels = labels
      results.scores = scores
      # create an empty bbox in InstanceData to avoid bugs when
      # calculating metrics.
      results.bboxes = results.scores.new_zeros(len(scores), 4)
  
      return results
  
imports: import warnings
  from typing import List, Optional, Tuple
  import mmcv
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.utils.misc import floordiv
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType
  from ..layers import mask_matrix_nms
  from ..utils import center_of_mass, generate_coordinate, multi_apply
  from .solo_head import SOLOHead
label_desc: Use image node_id 7 for calling the SOLOV2Head obj's underlying member method code with example usage: obj._predict_by_feat_single(kernel_preds, cls_scores, mask_feats, img_meta, cfg) and returns: results, results, empty_results, empty_results, empty_results