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: Compute corresponding GT box and classification targets for
  proposals.
  
  Args:
      flat_proposals (Tensor): Multi level points of a image.
      valid_flags (Tensor): Multi level valid flags of a image.
      gt_instances (InstanceData): It usually includes ``bboxes`` and
          ``labels`` attributes.
      gt_instances_ignore (InstanceData): It includes ``bboxes``
          attribute data that is ignored during training and testing.
      stage (str): 'init' or 'refine'. Generate target for
          init stage or refine stage. Defaults to 'init'.
      unmap_outputs (bool): Whether to map outputs back to
          the original set of anchors. Defaults to True.
  
  Returns:
      tuple:
  
          - labels (Tensor): Labels of each level.
          - label_weights (Tensor): Label weights of each level.
          - bbox_targets (Tensor): BBox targets of each level.
          - bbox_weights (Tensor): BBox weights of each level.
          - pos_inds (Tensor): positive samples indexes.
          - neg_inds (Tensor): negative samples indexes.
          - sampling_result (:obj:`SamplingResult`): Sampling results.
docstr_tok: ["Compute","corresponding","GT","box","and","classification","targets","for","proposals",".","Args",":","flat_proposals","(","Tensor",")",":","Multi","level","points","of","a","image",".","valid_flags","(","Tensor",")",":","Multi","level","valid","flags","of","a","image",".","gt_instances","(","InstanceData",")",":","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","gt_instances_ignore","(","InstanceData",")",":","It","includes","``","bboxes","``","attribute","data","that","is","ignored","during","training","and","testing",".","stage","(","str",")",":","'init","'","or","'refine","'",".","Generate","target","for","init","stage","or","refine","stage",".","Defaults","to","'init","'",".","unmap_outputs","(","bool",")",":","Whether","to","map","outputs","back","to","the","original","set","of","anchors",".","Defaults","to","True",".","Returns",":","tuple",":","-","labels","(","Tensor",")",":","Labels","of","each","level",".","-","label_weights","(","Tensor",")",":","Label","weights","of","each","level",".","-","bbox_targets","(","Tensor",")",":","BBox","targets","of","each","level",".","-","bbox_weights","(","Tensor",")",":","BBox","weights","of","each","level",".","-","pos_inds","(","Tensor",")",":","positive","samples","indexes",".","-","neg_inds","(","Tensor",")",":","negative","samples","indexes",".","-","sampling_result","(",":","obj",":","`","SamplingResult","`",")",":","Sampling","results","."]
code: def _get_targets_single(
      self,
      flat_proposals: Tensor,
      valid_flags: Tensor,
      gt_instances: InstanceData,
      gt_instances_ignore: InstanceData,
      stage: str = "init",
      unmap_outputs: bool = True,
  ) -> tuple:
      """Compute corresponding GT box and classification targets for
      proposals.
  
      Args:
          flat_proposals (Tensor): Multi level points of a image.
          valid_flags (Tensor): Multi level valid flags of a image.
          gt_instances (InstanceData): It usually includes ``bboxes`` and
              ``labels`` attributes.
          gt_instances_ignore (InstanceData): It includes ``bboxes``
              attribute data that is ignored during training and testing.
          stage (str): 'init' or 'refine'. Generate target for
              init stage or refine stage. Defaults to 'init'.
          unmap_outputs (bool): Whether to map outputs back to
              the original set of anchors. Defaults to True.
  
      Returns:
          tuple:
  
              - labels (Tensor): Labels of each level.
              - label_weights (Tensor): Label weights of each level.
              - bbox_targets (Tensor): BBox targets of each level.
              - bbox_weights (Tensor): BBox weights of each level.
              - pos_inds (Tensor): positive samples indexes.
              - neg_inds (Tensor): negative samples indexes.
              - sampling_result (:obj:`SamplingResult`): Sampling results.
      """
      inside_flags = valid_flags
      if not inside_flags.any():
          raise ValueError(
              "There is no valid proposal inside the image boundary. Please "
              "check the image size."
          )
      # assign gt and sample proposals
      proposals = flat_proposals[inside_flags, :]
      pred_instances = InstanceData(priors=proposals)
  
      if stage == "init":
          assigner = self.init_assigner
          pos_weight = self.train_cfg["init"]["pos_weight"]
      else:
          assigner = self.refine_assigner
          pos_weight = self.train_cfg["refine"]["pos_weight"]
  
      assign_result = assigner.assign(
          pred_instances, gt_instances, gt_instances_ignore
      )
      sampling_result = self.sampler.sample(
          assign_result, pred_instances, gt_instances
      )
  
      num_valid_proposals = proposals.shape[0]
      bbox_gt = proposals.new_zeros([num_valid_proposals, 4])
      pos_proposals = torch.zeros_like(proposals)
      proposals_weights = proposals.new_zeros([num_valid_proposals, 4])
      labels = proposals.new_full(
          (num_valid_proposals,), self.num_classes, dtype=torch.long
      )
      label_weights = proposals.new_zeros(
          num_valid_proposals, dtype=torch.float
      )
  
      pos_inds = sampling_result.pos_inds
      neg_inds = sampling_result.neg_inds
      if len(pos_inds) > 0:
          bbox_gt[pos_inds, :] = sampling_result.pos_gt_bboxes
          pos_proposals[pos_inds, :] = proposals[pos_inds, :]
          proposals_weights[pos_inds, :] = 1.0
  
          labels[pos_inds] = sampling_result.pos_gt_labels
          if pos_weight <= 0:
              label_weights[pos_inds] = 1.0
          else:
              label_weights[pos_inds] = pos_weight
      if len(neg_inds) > 0:
          label_weights[neg_inds] = 1.0
  
      # map up to original set of proposals
      if unmap_outputs:
          num_total_proposals = flat_proposals.size(0)
          labels = unmap(
              labels,
              num_total_proposals,
              inside_flags,
              fill=self.num_classes,
          )  # fill bg label
          label_weights = unmap(
              label_weights, num_total_proposals, inside_flags
          )
          bbox_gt = unmap(bbox_gt, num_total_proposals, inside_flags)
          pos_proposals = unmap(
              pos_proposals, num_total_proposals, inside_flags
          )
          proposals_weights = unmap(
              proposals_weights, num_total_proposals, inside_flags
          )
  
      return (
          labels,
          label_weights,
          bbox_gt,
          pos_proposals,
          proposals_weights,
          pos_inds,
          neg_inds,
          sampling_result,
      )
  
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 10 for calling the RepPointsHead obj's underlying member method code with example usage: obj._get_targets_single(flat_proposals, valid_flags, gt_instances, gt_instances_ignore, stage, unmap_outputs) and returns: labels,  label_weights,  bbox_gt,  pos_proposals,  proposals_weights,  pos_inds,  neg_inds,  sampling_result