class_docstr: Detection Head of RTMDet.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      with_objectness (bool): Whether to add an objectness branch.
          Defaults to True.
      act_cfg (:obj:`ConfigDict` or dict): Config dict for activation layer.
          Default: dict(type='ReLU')
class_docstr_tok: ["Detection","Head","of","RTMDet",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","with_objectness","(","bool",")",":","Whether","to","add","an","objectness","branch",".","Defaults","to","True",".","act_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='ReLU","'",")"]
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.
docstr_tok: ["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],
      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,
      )
      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)
  
      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)
      )
      return dict(loss_cls=losses_cls, loss_bbox=losses_bbox)
  
imports: from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule, Scale, is_norm
  from mmengine.model import bias_init_with_prob, constant_init, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import distance2bbox
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, reduce_mean
  from ..layers.transformer import inverse_sigmoid
  from ..task_modules import anchor_inside_flags
  from ..utils import images_to_levels, multi_apply, sigmoid_geometric_mean, unmap
  from .atss_head import ATSSHead
label_desc: Use image node_id 6 for calling the RTMDetHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: dict