class_docstr: SOLO mask head used in `SOLO: Segmenting Objects by Locations.
  
  <https://arxiv.org/abs/1912.04488>`_
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels. Used in child classes.
          Defaults to 256.
      stacked_convs (int): Number of stacking convs of the head.
          Defaults to 4.
      strides (tuple): Downsample factor of each feature map.
      scale_ranges (tuple[tuple[int, int]]): Area range of multiple
          level masks, in the format [(min1, max1), (min2, max2), ...].
          A range of (16, 64) means the area range between (16, 64).
      pos_scale (float): Constant scale factor to control the center region.
      num_grids (list[int]): Divided image into a uniform grids, each
          feature map has a different grid value. The number of output
          channels is grid ** 2. Defaults to [40, 36, 24, 16, 12].
      cls_down_index (int): The index of downsample operation in
          classification branch. Defaults to 0.
      loss_mask (dict): Config of mask loss.
      loss_cls (dict): Config of classification loss.
      norm_cfg (dict): Dictionary to construct and config norm layer.
          Defaults to norm_cfg=dict(type='GN', num_groups=32,
          requires_grad=True).
      train_cfg (dict): Training config of head.
      test_cfg (dict): Testing config of head.
      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:
      cls_scores (Tensor): Classification score of all points
          in single image, has shape (num_points, num_classes).
      mask_preds (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,
      cls_scores: Tensor,
      mask_preds: Tensor,
      img_meta: dict,
      cfg: OptConfigType = None,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      mask results.
  
      Args:
          cls_scores (Tensor): Classification score of all points
              in single image, has shape (num_points, num_classes).
          mask_preds (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(cls_scores) == len(mask_preds)
  
      featmap_size = mask_preds.size()[-2:]
  
      h, w = img_meta["img_shape"][:2]
      upsampled_size = (featmap_size[0] * 4, featmap_size[1] * 4)
  
      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])
  
      inds = score_mask.nonzero()
      cls_labels = inds[:, 1]
  
      # Filter the mask mask with an area is smaller than
      # stride of corresponding feature level
      lvl_interval = (
          cls_labels.new_tensor(self.num_grids).pow(2).cumsum(0)
      )
      strides = cls_scores.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_preds = mask_preds[inds[:, 0]]
  
      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,
      )
      # mask_matrix_nms may return an empty Tensor
      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"
      )[:, :, :h, :w]
      mask_preds = F.interpolate(
          mask_preds, size=img_meta["ori_shape"][:2], mode="bilinear"
      ).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: 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.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 .base_mask_head import BaseMaskHead
label_desc: Use image node_id 8 for calling the SOLOHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_scores, mask_preds, img_meta, cfg) and returns: results, results, empty_results, empty_results, empty_results