class_docstr: RepPoint head.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      point_feat_channels (int): Number of channels of points features.
      num_points (int): Number of points.
      gradient_mul (float): The multiplier to gradients from
          points refinement and recognition.
      point_strides (Sequence[int]): points strides.
      point_base_scale (int): bbox scale for assigning labels.
      loss_cls (:obj:`ConfigDict` or dict): Config of classification loss.
      loss_bbox_init (:obj:`ConfigDict` or dict): Config of initial points
          loss.
      loss_bbox_refine (:obj:`ConfigDict` or dict): Config of points loss in
          refinement.
      use_grid_points (bool): If we use bounding box representation, the
      reppoints is represented as grid points on the bounding box.
      center_init (bool): Whether to use center point assignment.
      transform_method (str): The methods to transform RepPoints to bbox.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict]): Initialization config dict.
class_docstr_tok: ["RepPoint","head",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","point_feat_channels","(","int",")",":","Number","of","channels","of","points","features",".","num_points","(","int",")",":","Number","of","points",".","gradient_mul","(","float",")",":","The","multiplier","to","gradients","from","points","refinement","and","recognition",".","point_strides","(","Sequence","[","int","]",")",":","points","strides",".","point_base_scale","(","int",")",":","bbox","scale","for","assigning","labels",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","classification","loss",".","loss_bbox_init","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","initial","points","loss",".","loss_bbox_refine","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","points","loss","in","refinement",".","use_grid_points","(","bool",")",":","If","we","use","bounding","box","representation",",","the","reppoints","is","represented","as","grid","points","on","the","bounding","box",".","center_init","(","bool",")",":","Whether","to","use","center","point","assignment",".","transform_method","(","str",")",":","The","methods","to","transform","RepPoints","to","bbox",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",")",":","Initialization","config","dict","."]
docstr: Calculate the loss based on the features extracted by the detection
  head.
  
  Args:
      cls_scores (list[Tensor]): Box scores for each scale level,
          each is a 4D-tensor, of shape (batch_size, num_classes, h, w).
      pts_preds_init (list[Tensor]): Points for each scale level, each is
          a 3D-tensor, of shape (batch_size, h_i * w_i, num_points * 2).
      pts_preds_refine (list[Tensor]): Points refined for each scale
          level, each is a 3D-tensor, of shape
          (batch_size, h_i * w_i, num_points * 2).
      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: ["Calculate","the","loss","based","on","the","features","extracted","by","the","detection","head",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","each","scale","level",",","each","is","a","4D-tensor",",","of","shape","(","batch_size",",","num_classes",",","h",",","w",")",".","pts_preds_init","(","list","[","Tensor","]",")",":","Points","for","each","scale","level",",","each","is","a","3D-tensor",",","of","shape","(","batch_size",",","h_i","*","w_i",",","num_points","*","2",")",".","pts_preds_refine","(","list","[","Tensor","]",")",":","Points","refined","for","each","scale","level",",","each","is","a","3D-tensor",",","of","shape","(","batch_size",",","h_i","*","w_i",",","num_points","*","2",")",".","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],
      pts_preds_init: List[Tensor],
      pts_preds_refine: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> Dict[str, Tensor]:
      """Calculate the loss based on the features extracted by the detection
      head.
  
      Args:
          cls_scores (list[Tensor]): Box scores for each scale level,
              each is a 4D-tensor, of shape (batch_size, num_classes, h, w).
          pts_preds_init (list[Tensor]): Points for each scale level, each is
              a 3D-tensor, of shape (batch_size, h_i * w_i, num_points * 2).
          pts_preds_refine (list[Tensor]): Points refined for each scale
              level, each is a 3D-tensor, of shape
              (batch_size, h_i * w_i, num_points * 2).
          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.
      """
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      device = cls_scores[0].device
  
      # target for initial stage
      center_list, valid_flag_list = self.get_points(
          featmap_sizes, batch_img_metas, device
      )
      pts_coordinate_preds_init = self.offset_to_pts(
          center_list, pts_preds_init
      )
      if self.train_cfg["init"]["assigner"]["type"] == "PointAssigner":
          # Assign target for center list
          candidate_list = center_list
      else:
          # transform center list to bbox list and
          #   assign target for bbox list
          bbox_list = self.centers_to_bboxes(center_list)
          candidate_list = bbox_list
      cls_reg_targets_init = self.get_targets(
          proposals_list=candidate_list,
          valid_flag_list=valid_flag_list,
          batch_gt_instances=batch_gt_instances,
          batch_img_metas=batch_img_metas,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
          stage="init",
          return_sampling_results=False,
      )
      (
          *_,
          bbox_gt_list_init,
          candidate_list_init,
          bbox_weights_list_init,
          avg_factor_init,
      ) = cls_reg_targets_init
  
      # target for refinement stage
      center_list, valid_flag_list = self.get_points(
          featmap_sizes, batch_img_metas, device
      )
      pts_coordinate_preds_refine = self.offset_to_pts(
          center_list, pts_preds_refine
      )
      bbox_list = []
      for i_img, center in enumerate(center_list):
          bbox = []
          for i_lvl in range(len(pts_preds_refine)):
              bbox_preds_init = self.points2bbox(
                  pts_preds_init[i_lvl].detach()
              )
              bbox_shift = bbox_preds_init * self.point_strides[i_lvl]
              bbox_center = torch.cat(
                  [center[i_lvl][:, :2], center[i_lvl][:, :2]], dim=1
              )
              bbox.append(
                  bbox_center
                  + bbox_shift[i_img].permute(1, 2, 0).reshape(-1, 4)
              )
          bbox_list.append(bbox)
      cls_reg_targets_refine = self.get_targets(
          proposals_list=bbox_list,
          valid_flag_list=valid_flag_list,
          batch_gt_instances=batch_gt_instances,
          batch_img_metas=batch_img_metas,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
          stage="refine",
          return_sampling_results=False,
      )
      (
          labels_list,
          label_weights_list,
          bbox_gt_list_refine,
          candidate_list_refine,
          bbox_weights_list_refine,
          avg_factor_refine,
      ) = cls_reg_targets_refine
  
      # compute loss
      losses_cls, losses_pts_init, losses_pts_refine = multi_apply(
          self.loss_by_feat_single,
          cls_scores,
          pts_coordinate_preds_init,
          pts_coordinate_preds_refine,
          labels_list,
          label_weights_list,
          bbox_gt_list_init,
          bbox_weights_list_init,
          bbox_gt_list_refine,
          bbox_weights_list_refine,
          self.point_strides,
          avg_factor_init=avg_factor_init,
          avg_factor_refine=avg_factor_refine,
      )
      loss_dict_all = {
          "loss_cls": losses_cls,
          "loss_pts_init": losses_pts_init,
          "loss_pts_refine": losses_pts_refine,
      }
      return loss_dict_all
  
imports: from typing import Dict, List, Sequence, Tuple
  import numpy
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmcv.ops import DeformConv2d
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptInstanceList
  from ..task_modules.prior_generators import MlvlPointGenerator
  from ..task_modules.samplers import PseudoSampler
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply, unmap
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 13 for calling the RepPointsHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, pts_preds_init, pts_preds_refine, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: loss_dict_all