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: Compute losses of the head.
  
  Args:
      cls_scores (list[Tensor]): Box scores for each scale level
          Has shape (N, num_anchors * num_classes, H, W)
      bbox_preds (list[Tensor]): Decoded box for each scale
          level with shape (N, num_anchors * 4, H, W) in
          [tl_x, tl_y, br_x, br_y] format.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance.  It usually includes ``bboxes`` and ``labels``
          attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      batch_gt_instances_ignore (list[:obj:`InstanceData`], Optional):
          Batch of gt_instances_ignore. It includes ``bboxes`` attribute
          data that is ignored during training and testing.
          Defaults to None.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
code: def loss_by_feat(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      kernel_preds: List[Tensor],
      mask_feat: Tensor,
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ):
      """Compute losses of the head.
  
      Args:
          cls_scores (list[Tensor]): Box scores for each scale level
              Has shape (N, num_anchors * num_classes, H, W)
          bbox_preds (list[Tensor]): Decoded box for each scale
              level with shape (N, num_anchors * 4, H, W) in
              [tl_x, tl_y, br_x, br_y] format.
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance.  It usually includes ``bboxes`` and ``labels``
              attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          batch_gt_instances_ignore (list[:obj:`InstanceData`], Optional):
              Batch of gt_instances_ignore. It includes ``bboxes`` attribute
              data that is ignored during training and testing.
              Defaults to None.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      num_imgs = len(batch_img_metas)
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      assert len(featmap_sizes) == self.prior_generator.num_levels
  
      device = cls_scores[0].device
      anchor_list, valid_flag_list = self.get_anchors(
          featmap_sizes, batch_img_metas, device=device
      )
      flatten_cls_scores = torch.cat(
          [
              cls_score.permute(0, 2, 3, 1).reshape(
                  num_imgs, -1, self.cls_out_channels
              )
              for cls_score in cls_scores
          ],
          1,
      )
      flatten_kernels = torch.cat(
          [
              kernel_pred.permute(0, 2, 3, 1).reshape(
                  num_imgs, -1, self.num_gen_params
              )
              for kernel_pred in kernel_preds
          ],
          1,
      )
      decoded_bboxes = []
      for anchor, bbox_pred in zip(anchor_list[0], bbox_preds):
          anchor = anchor.reshape(-1, 4)
          bbox_pred = bbox_pred.permute(0, 2, 3, 1).reshape(
              num_imgs, -1, 4
          )
          bbox_pred = distance2bbox(anchor, bbox_pred)
          decoded_bboxes.append(bbox_pred)
  
      flatten_bboxes = torch.cat(decoded_bboxes, 1)
      for gt_instances in batch_gt_instances:
          gt_instances.masks = gt_instances.masks.to_tensor(
              dtype=torch.bool, device=device
          )
  
      cls_reg_targets = self.get_targets(
          flatten_cls_scores,
          flatten_bboxes,
          anchor_list,
          valid_flag_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
      )
      (
          anchor_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          assign_metrics_list,
          sampling_results_list,
      ) = cls_reg_targets
  
      (
          losses_cls,
          losses_bbox,
          cls_avg_factors,
          bbox_avg_factors,
      ) = multi_apply(
          self.loss_by_feat_single,
          cls_scores,
          decoded_bboxes,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          assign_metrics_list,
          self.prior_generator.strides,
      )
  
      cls_avg_factor = (
          reduce_mean(sum(cls_avg_factors)).clamp_(min=1).item()
      )
      losses_cls = list(map(lambda x: x / cls_avg_factor, losses_cls))
  
      bbox_avg_factor = (
          reduce_mean(sum(bbox_avg_factors)).clamp_(min=1).item()
      )
      losses_bbox = list(
          map(lambda x: x / bbox_avg_factor, losses_bbox)
      )
  
      loss_mask = self.loss_mask_by_feat(
          mask_feat,
          flatten_kernels,
          sampling_results_list,
          batch_gt_instances,
      )
      loss = dict(
          loss_cls=losses_cls,
          loss_bbox=losses_bbox,
          loss_mask=loss_mask,
      )
      return loss
  
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 10 for calling the RTMDetInsHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, kernel_preds, mask_feat, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: loss