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 batch of output features extracted from the head into
  bbox results.
  
  Note: When score_factors is not None, the cls_scores are
  usually multiplied by it then obtain the real score used in NMS,
  such as CenterNess in FCOS, IoU branch in ATSS.
  
  Args:
      cls_scores (list[Tensor]): Classification scores for all
          scale levels, each is a 4D-tensor, has shape
          (batch_size, num_priors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas for all
          scale levels, each is a 4D-tensor, has shape
          (batch_size, num_priors * 4, H, W).
      kernel_preds (list[Tensor]): Kernel predictions of dynamic
          convs for all scale levels, each is a 4D-tensor, has shape
          (batch_size, num_params, H, W).
      mask_feat (Tensor): Mask prototype features extracted from the
          mask head, has shape (batch_size, num_prototypes, H, W).
      score_factors (list[Tensor], optional): Score factor for
          all scale level, each is a 4D-tensor, has shape
          (batch_size, num_priors * 1, H, W). Defaults to None.
      batch_img_metas (list[dict], Optional): Batch image meta info.
          Defaults to None.
      cfg (ConfigDict, optional): Test / postprocessing
          configuration, if None, test_cfg would be used.
          Defaults to None.
      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:
      list[:obj:`InstanceData`]: Object 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(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      kernel_preds: List[Tensor],
      mask_feat: Tensor,
      score_factors: Optional[List[Tensor]] = None,
      batch_img_metas: Optional[List[dict]] = None,
      cfg: Optional[ConfigType] = None,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> InstanceList:
      """Transform a batch of output features extracted from the head into
      bbox results.
  
      Note: When score_factors is not None, the cls_scores are
      usually multiplied by it then obtain the real score used in NMS,
      such as CenterNess in FCOS, IoU branch in ATSS.
  
      Args:
          cls_scores (list[Tensor]): Classification scores for all
              scale levels, each is a 4D-tensor, has shape
              (batch_size, num_priors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas for all
              scale levels, each is a 4D-tensor, has shape
              (batch_size, num_priors * 4, H, W).
          kernel_preds (list[Tensor]): Kernel predictions of dynamic
              convs for all scale levels, each is a 4D-tensor, has shape
              (batch_size, num_params, H, W).
          mask_feat (Tensor): Mask prototype features extracted from the
              mask head, has shape (batch_size, num_prototypes, H, W).
          score_factors (list[Tensor], optional): Score factor for
              all scale level, each is a 4D-tensor, has shape
              (batch_size, num_priors * 1, H, W). Defaults to None.
          batch_img_metas (list[dict], Optional): Batch image meta info.
              Defaults to None.
          cfg (ConfigDict, optional): Test / postprocessing
              configuration, if None, test_cfg would be used.
              Defaults to None.
          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:
          list[:obj:`InstanceData`]: Object 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).
      """
      assert len(cls_scores) == len(bbox_preds)
  
      if score_factors is None:
          # e.g. Retina, FreeAnchor, Foveabox, etc.
          with_score_factors = False
      else:
          # e.g. FCOS, PAA, ATSS, AutoAssign, etc.
          with_score_factors = True
          assert len(cls_scores) == len(score_factors)
  
      num_levels = len(cls_scores)
  
      featmap_sizes = [
          cls_scores[i].shape[-2:] for i in range(num_levels)
      ]
      mlvl_priors = self.prior_generator.grid_priors(
          featmap_sizes,
          dtype=cls_scores[0].dtype,
          device=cls_scores[0].device,
          with_stride=True,
      )
  
      result_list = []
  
      for img_id in range(len(batch_img_metas)):
          img_meta = batch_img_metas[img_id]
          cls_score_list = select_single_mlvl(
              cls_scores, img_id, detach=True
          )
          bbox_pred_list = select_single_mlvl(
              bbox_preds, img_id, detach=True
          )
          kernel_pred_list = select_single_mlvl(
              kernel_preds, img_id, detach=True
          )
          if with_score_factors:
              score_factor_list = select_single_mlvl(
                  score_factors, img_id, detach=True
              )
          else:
              score_factor_list = [None for _ in range(num_levels)]
  
          results = self._predict_by_feat_single(
              cls_score_list=cls_score_list,
              bbox_pred_list=bbox_pred_list,
              kernel_pred_list=kernel_pred_list,
              mask_feat=mask_feat[img_id],
              score_factor_list=score_factor_list,
              mlvl_priors=mlvl_priors,
              img_meta=img_meta,
              cfg=cfg,
              rescale=rescale,
              with_nms=with_nms,
          )
          result_list.append(results)
      return result_list
  
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 4 for calling the RTMDetInsHead obj's underlying member method code with example usage: obj.predict_by_feat(cls_scores, bbox_preds, kernel_preds, mask_feat, score_factors, batch_img_metas, cfg, rescale, with_nms) and returns: result_list