class_docstr: Detection Head of RTMDet-Ins.
  
  Args:
      num_prototypes (int): Number of mask prototype features extracted
          from the mask head. Defaults to 8.
      dyconv_channels (int): Channel of the dynamic conv layers.
          Defaults to 8.
      num_dyconvs (int): Number of the dynamic convolution layers.
          Defaults to 3.
      mask_loss_stride (int): Down sample stride of the masks for loss
          computation. Defaults to 4.
      loss_mask (:obj:`ConfigDict` or dict): Config dict for mask loss.
docstr: Transform a single image's features extracted from the head into
  bbox and mask results.
  
  Args:
      cls_score_list (list[Tensor]): Box scores from all scale
          levels of a single image, each item has shape
          (num_priors * num_classes, H, W).
      bbox_pred_list (list[Tensor]): Box energies / deltas from
          all scale levels of a single image, each item has shape
          (num_priors * 4, H, W).
      kernel_preds (list[Tensor]): Kernel predictions of dynamic
          convs for all scale levels of a single image, each is a
          4D-tensor, has shape (num_params, H, W).
      mask_feat (Tensor): Mask prototype features of a single image
          extracted from the mask head, has shape (num_prototypes, H, W).
      score_factor_list (list[Tensor]): Score factor from all scale
          levels of a single image, each item has shape
          (num_priors * 1, H, W).
      mlvl_priors (list[Tensor]): Each element in the list is
          the priors of a single level in feature pyramid. In all
          anchor-based methods, it has shape (num_priors, 4). In
          all anchor-free methods, it has shape (num_priors, 2)
          when `with_stride=True`, otherwise it still has shape
          (num_priors, 4).
      img_meta (dict): Image meta info.
      cfg (mmengine.Config): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
      with_nms (bool): If True, do nms before return boxes.
          Defaults to True.
  
  Returns:
      :obj:`InstanceData`: Detection results of each image
      after the post process.
      Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor): Has a shape (num_instances, h, w).
code: def _predict_by_feat_single(
      self,
      cls_score_list: List[Tensor],
      bbox_pred_list: List[Tensor],
      kernel_pred_list: List[Tensor],
      mask_feat: Tensor,
      score_factor_list: List[Tensor],
      mlvl_priors: List[Tensor],
      img_meta: dict,
      cfg: ConfigType,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox and mask results.
  
      Args:
          cls_score_list (list[Tensor]): Box scores from all scale
              levels of a single image, each item has shape
              (num_priors * num_classes, H, W).
          bbox_pred_list (list[Tensor]): Box energies / deltas from
              all scale levels of a single image, each item has shape
              (num_priors * 4, H, W).
          kernel_preds (list[Tensor]): Kernel predictions of dynamic
              convs for all scale levels of a single image, each is a
              4D-tensor, has shape (num_params, H, W).
          mask_feat (Tensor): Mask prototype features of a single image
              extracted from the mask head, has shape (num_prototypes, H, W).
          score_factor_list (list[Tensor]): Score factor from all scale
              levels of a single image, each item has shape
              (num_priors * 1, H, W).
          mlvl_priors (list[Tensor]): Each element in the list is
              the priors of a single level in feature pyramid. In all
              anchor-based methods, it has shape (num_priors, 4). In
              all anchor-free methods, it has shape (num_priors, 2)
              when `with_stride=True`, otherwise it still has shape
              (num_priors, 4).
          img_meta (dict): Image meta info.
          cfg (mmengine.Config): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
          with_nms (bool): If True, do nms before return boxes.
              Defaults to True.
  
      Returns:
          :obj:`InstanceData`: Detection results of each image
          after the post process.
          Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor): Has a shape (num_instances, h, w).
      """
      if score_factor_list[0] is None:
          # e.g. Retina, FreeAnchor, etc.
          with_score_factors = False
      else:
          # e.g. FCOS, PAA, ATSS, etc.
          with_score_factors = True
  
      cfg = self.test_cfg if cfg is None else cfg
      cfg = copy.deepcopy(cfg)
      img_shape = img_meta["img_shape"]
      nms_pre = cfg.get("nms_pre", -1)
  
      mlvl_bbox_preds = []
      mlvl_kernels = []
      mlvl_valid_priors = []
      mlvl_scores = []
      mlvl_labels = []
      if with_score_factors:
          mlvl_score_factors = []
      else:
          mlvl_score_factors = None
  
      for level_idx, (
          cls_score,
          bbox_pred,
          kernel_pred,
          score_factor,
          priors,
      ) in enumerate(
          zip(
              cls_score_list,
              bbox_pred_list,
              kernel_pred_list,
              score_factor_list,
              mlvl_priors,
          )
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          dim = self.bbox_coder.encode_size
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, dim)
          if with_score_factors:
              score_factor = (
                  score_factor.permute(1, 2, 0).reshape(-1).sigmoid()
              )
          cls_score = cls_score.permute(1, 2, 0).reshape(
              -1, self.cls_out_channels
          )
          kernel_pred = kernel_pred.permute(1, 2, 0).reshape(
              -1, self.num_gen_params
          )
          if self.use_sigmoid_cls:
              scores = cls_score.sigmoid()
          else:
              # remind that we set FG labels to [0, num_class-1]
              # since mmdet v2.0
              # BG cat_id: num_class
              scores = cls_score.softmax(-1)[:, :-1]
  
          # After https://github.com/open-mmlab/mmdetection/pull/6268/,
          # this operation keeps fewer bboxes under the same `nms_pre`.
          # There is no difference in performance for most models. If you
          # find a slight drop in performance, you can set a larger
          # `nms_pre` than before.
          score_thr = cfg.get("score_thr", 0)
  
          results = filter_scores_and_topk(
              scores,
              score_thr,
              nms_pre,
              dict(
                  bbox_pred=bbox_pred,
                  priors=priors,
                  kernel_pred=kernel_pred,
              ),
          )
          scores, labels, keep_idxs, filtered_results = results
  
          bbox_pred = filtered_results["bbox_pred"]
          priors = filtered_results["priors"]
          kernel_pred = filtered_results["kernel_pred"]
  
          if with_score_factors:
              score_factor = score_factor[keep_idxs]
  
          mlvl_bbox_preds.append(bbox_pred)
          mlvl_valid_priors.append(priors)
          mlvl_scores.append(scores)
          mlvl_labels.append(labels)
          mlvl_kernels.append(kernel_pred)
  
          if with_score_factors:
              mlvl_score_factors.append(score_factor)
  
      bbox_pred = torch.cat(mlvl_bbox_preds)
      priors = cat_boxes(mlvl_valid_priors)
      bboxes = self.bbox_coder.decode(
          priors[..., :2], bbox_pred, max_shape=img_shape
      )
  
      results = InstanceData()
      results.bboxes = bboxes
      results.priors = priors
      results.scores = torch.cat(mlvl_scores)
      results.labels = torch.cat(mlvl_labels)
      results.kernels = torch.cat(mlvl_kernels)
      if with_score_factors:
          results.score_factors = torch.cat(mlvl_score_factors)
  
      return self._bbox_mask_post_process(
          results=results,
          mask_feat=mask_feat,
          cfg=cfg,
          rescale=rescale,
          with_nms=with_nms,
          img_meta=img_meta,
      )
  
imports: import copy
  import math
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, is_norm
  from mmcv.ops import batched_nms
  from mmengine.model import BaseModule, bias_init_with_prob, constant_init, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.layers.transformer import inverse_sigmoid
  from mmdet.models.utils import filter_scores_and_topk, multi_apply, select_single_mlvl, sigmoid_geometric_mean
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes, distance2bbox, get_box_tensor, get_box_wh, scale_boxes
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, reduce_mean
  from .rtmdet_head import RTMDetHead
label_desc: Use image node_id 5 for calling the RTMDetInsHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_score_list, bbox_pred_list, kernel_pred_list, mask_feat, score_factor_list, mlvl_priors, img_meta, cfg, rescale, with_nms) and returns: self