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 of a single scale level based on the features
  extracted by the detection head.
  
  Args:
      cls_score (Tensor): Box scores for each scale level
          Has shape (N, num_classes, h_i, w_i).
      pts_pred_init (Tensor): Points of shape
          (batch_size, h_i * w_i, num_points * 2).
      pts_pred_refine (Tensor): Points refined of shape
          (batch_size, h_i * w_i, num_points * 2).
      labels (Tensor): Ground truth class indices with shape
          (batch_size, h_i * w_i).
      label_weights (Tensor): Label weights of shape
          (batch_size, h_i * w_i).
      bbox_gt_init (Tensor): BBox regression targets in the init stage
          of shape (batch_size, h_i * w_i, 4).
      bbox_weights_init (Tensor): BBox regression loss weights in the
          init stage of shape (batch_size, h_i * w_i, 4).
      bbox_gt_refine (Tensor): BBox regression targets in the refine
          stage of shape (batch_size, h_i * w_i, 4).
      bbox_weights_refine (Tensor): BBox regression loss weights in the
          refine stage of shape (batch_size, h_i * w_i, 4).
      stride (int): Point stride.
      avg_factor_init (int): Average factor that is used to average
          the loss in the init stage.
      avg_factor_refine (int): Average factor that is used to average
          the loss in the refine stage.
  
  Returns:
      Tuple[Tensor]: loss components.
docstr_tok: ["Calculate","the","loss","of","a","single","scale","level","based","on","the","features","extracted","by","the","detection","head",".","Args",":","cls_score","(","Tensor",")",":","Box","scores","for","each","scale","level","Has","shape","(","N",",","num_classes",",","h_i",",","w_i",")",".","pts_pred_init","(","Tensor",")",":","Points","of","shape","(","batch_size",",","h_i","*","w_i",",","num_points","*","2",")",".","pts_pred_refine","(","Tensor",")",":","Points","refined","of","shape","(","batch_size",",","h_i","*","w_i",",","num_points","*","2",")",".","labels","(","Tensor",")",":","Ground","truth","class","indices","with","shape","(","batch_size",",","h_i","*","w_i",")",".","label_weights","(","Tensor",")",":","Label","weights","of","shape","(","batch_size",",","h_i","*","w_i",")",".","bbox_gt_init","(","Tensor",")",":","BBox","regression","targets","in","the","init","stage","of","shape","(","batch_size",",","h_i","*","w_i",",","4",")",".","bbox_weights_init","(","Tensor",")",":","BBox","regression","loss","weights","in","the","init","stage","of","shape","(","batch_size",",","h_i","*","w_i",",","4",")",".","bbox_gt_refine","(","Tensor",")",":","BBox","regression","targets","in","the","refine","stage","of","shape","(","batch_size",",","h_i","*","w_i",",","4",")",".","bbox_weights_refine","(","Tensor",")",":","BBox","regression","loss","weights","in","the","refine","stage","of","shape","(","batch_size",",","h_i","*","w_i",",","4",")",".","stride","(","int",")",":","Point","stride",".","avg_factor_init","(","int",")",":","Average","factor","that","is","used","to","average","the","loss","in","the","init","stage",".","avg_factor_refine","(","int",")",":","Average","factor","that","is","used","to","average","the","loss","in","the","refine","stage",".","Returns",":","Tuple","[","Tensor","]",":","loss","components","."]
code: def loss_by_feat_single(
      self,
      cls_score: Tensor,
      pts_pred_init: Tensor,
      pts_pred_refine: Tensor,
      labels: Tensor,
      label_weights,
      bbox_gt_init: Tensor,
      bbox_weights_init: Tensor,
      bbox_gt_refine: Tensor,
      bbox_weights_refine: Tensor,
      stride: int,
      avg_factor_init: int,
      avg_factor_refine: int,
  ) -> Tuple[Tensor]:
      """Calculate the loss of a single scale level based on the features
      extracted by the detection head.
  
      Args:
          cls_score (Tensor): Box scores for each scale level
              Has shape (N, num_classes, h_i, w_i).
          pts_pred_init (Tensor): Points of shape
              (batch_size, h_i * w_i, num_points * 2).
          pts_pred_refine (Tensor): Points refined of shape
              (batch_size, h_i * w_i, num_points * 2).
          labels (Tensor): Ground truth class indices with shape
              (batch_size, h_i * w_i).
          label_weights (Tensor): Label weights of shape
              (batch_size, h_i * w_i).
          bbox_gt_init (Tensor): BBox regression targets in the init stage
              of shape (batch_size, h_i * w_i, 4).
          bbox_weights_init (Tensor): BBox regression loss weights in the
              init stage of shape (batch_size, h_i * w_i, 4).
          bbox_gt_refine (Tensor): BBox regression targets in the refine
              stage of shape (batch_size, h_i * w_i, 4).
          bbox_weights_refine (Tensor): BBox regression loss weights in the
              refine stage of shape (batch_size, h_i * w_i, 4).
          stride (int): Point stride.
          avg_factor_init (int): Average factor that is used to average
              the loss in the init stage.
          avg_factor_refine (int): Average factor that is used to average
              the loss in the refine stage.
  
      Returns:
          Tuple[Tensor]: loss components.
      """
      # classification loss
      labels = labels.reshape(-1)
      label_weights = label_weights.reshape(-1)
      cls_score = cls_score.permute(0, 2, 3, 1).reshape(
          -1, self.cls_out_channels
      )
      cls_score = cls_score.contiguous()
      loss_cls = self.loss_cls(
          cls_score, labels, label_weights, avg_factor=avg_factor_refine
      )
  
      # points loss
      bbox_gt_init = bbox_gt_init.reshape(-1, 4)
      bbox_weights_init = bbox_weights_init.reshape(-1, 4)
      bbox_pred_init = self.points2bbox(
          pts_pred_init.reshape(-1, 2 * self.num_points), y_first=False
      )
      bbox_gt_refine = bbox_gt_refine.reshape(-1, 4)
      bbox_weights_refine = bbox_weights_refine.reshape(-1, 4)
      bbox_pred_refine = self.points2bbox(
          pts_pred_refine.reshape(-1, 2 * self.num_points),
          y_first=False,
      )
      normalize_term = self.point_base_scale * stride
      loss_pts_init = self.loss_bbox_init(
          bbox_pred_init / normalize_term,
          bbox_gt_init / normalize_term,
          bbox_weights_init,
          avg_factor=avg_factor_init,
      )
      loss_pts_refine = self.loss_bbox_refine(
          bbox_pred_refine / normalize_term,
          bbox_gt_refine / normalize_term,
          bbox_weights_refine,
          avg_factor=avg_factor_refine,
      )
      return loss_cls, loss_pts_init, loss_pts_refine
  
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 12 for calling the RepPointsHead obj's underlying member method code with example usage: obj.loss_by_feat_single(cls_score, pts_pred_init, pts_pred_refine, labels, label_weights, bbox_gt_init, bbox_weights_init, bbox_gt_refine, bbox_weights_refine, stride, avg_factor_init, avg_factor_refine) and returns: loss_cls,  loss_pts_init,  loss_pts_refine