class_docstr: Simplest RoI head, with only two fc layers for classification and
  regression respectively.
class_docstr_tok: ["Simplest","RoI","head",",","with","only","two","fc","layers","for","classification","and","regression","respectively","."]
docstr: Calculate the ground truth for proposals in the single image
  according to the sampling results.
  
  Args:
      pos_priors (Tensor): Contains all the positive boxes,
          has shape (num_pos, 4), the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      neg_priors (Tensor): Contains all the negative boxes,
          has shape (num_neg, 4), the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      pos_gt_bboxes (Tensor): Contains gt_boxes for
          all positive samples, has shape (num_pos, 4),
          the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      pos_gt_labels (Tensor): Contains gt_labels for
          all positive samples, has shape (num_pos, ).
      cfg (obj:`ConfigDict`): `train_cfg` of R-CNN.
  
  Returns:
      Tuple[Tensor]: Ground truth for proposals
      in a single image. Containing the following Tensors:
  
          - labels(Tensor): Gt_labels for all proposals, has
            shape (num_proposals,).
          - label_weights(Tensor): Labels_weights for all
            proposals, has shape (num_proposals,).
          - bbox_targets(Tensor):Regression target for all
            proposals, has shape (num_proposals, 4), the
            last dimension 4 represents [tl_x, tl_y, br_x, br_y].
          - bbox_weights(Tensor):Regression weights for all
            proposals, has shape (num_proposals, 4).
docstr_tok: ["Calculate","the","ground","truth","for","proposals","in","the","single","image","according","to","the","sampling","results",".","Args",":","pos_priors","(","Tensor",")",":","Contains","all","the","positive","boxes",",","has","shape","(","num_pos",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","neg_priors","(","Tensor",")",":","Contains","all","the","negative","boxes",",","has","shape","(","num_neg",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","pos_gt_bboxes","(","Tensor",")",":","Contains","gt_boxes","for","all","positive","samples",",","has","shape","(","num_pos",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","pos_gt_labels","(","Tensor",")",":","Contains","gt_labels","for","all","positive","samples",",","has","shape","(","num_pos",",",")",".","cfg","(","obj",":","`","ConfigDict","`",")",":","`","train_cfg","`","of","R-CNN",".","Returns",":","Tuple","[","Tensor","]",":","Ground","truth","for","proposals","in","a","single","image",".","Containing","the","following","Tensors",":","-","labels","(","Tensor",")",":","Gt_labels","for","all","proposals",",","has","shape","(","num_proposals",",",")",".","-","label_weights","(","Tensor",")",":","Labels_weights","for","all","proposals",",","has","shape","(","num_proposals",",",")",".","-","bbox_targets","(","Tensor",")",":","Regression","target","for","all","proposals",",","has","shape","(","num_proposals",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","-","bbox_weights","(","Tensor",")",":","Regression","weights","for","all","proposals",",","has","shape","(","num_proposals",",","4",")","."]
code: def _get_targets_single(
      self,
      pos_priors: Tensor,
      neg_priors: Tensor,
      pos_gt_bboxes: Tensor,
      pos_gt_labels: Tensor,
      cfg: ConfigDict,
  ) -> tuple:
      """Calculate the ground truth for proposals in the single image
      according to the sampling results.
  
      Args:
          pos_priors (Tensor): Contains all the positive boxes,
              has shape (num_pos, 4), the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          neg_priors (Tensor): Contains all the negative boxes,
              has shape (num_neg, 4), the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          pos_gt_bboxes (Tensor): Contains gt_boxes for
              all positive samples, has shape (num_pos, 4),
              the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          pos_gt_labels (Tensor): Contains gt_labels for
              all positive samples, has shape (num_pos, ).
          cfg (obj:`ConfigDict`): `train_cfg` of R-CNN.
  
      Returns:
          Tuple[Tensor]: Ground truth for proposals
          in a single image. Containing the following Tensors:
  
              - labels(Tensor): Gt_labels for all proposals, has
                shape (num_proposals,).
              - label_weights(Tensor): Labels_weights for all
                proposals, has shape (num_proposals,).
              - bbox_targets(Tensor):Regression target for all
                proposals, has shape (num_proposals, 4), the
                last dimension 4 represents [tl_x, tl_y, br_x, br_y].
              - bbox_weights(Tensor):Regression weights for all
                proposals, has shape (num_proposals, 4).
      """
      num_pos = pos_priors.size(0)
      num_neg = neg_priors.size(0)
      num_samples = num_pos + num_neg
  
      # original implementation uses new_zeros since BG are set to be 0
      # now use empty & fill because BG cat_id = num_classes,
      # FG cat_id = [0, num_classes-1]
      labels = pos_priors.new_full(
          (num_samples,), self.num_classes, dtype=torch.long
      )
      reg_dim = (
          pos_gt_bboxes.size(-1)
          if self.reg_decoded_bbox
          else self.bbox_coder.encode_size
      )
      label_weights = pos_priors.new_zeros(num_samples)
      bbox_targets = pos_priors.new_zeros(num_samples, reg_dim)
      bbox_weights = pos_priors.new_zeros(num_samples, reg_dim)
      if num_pos > 0:
          labels[:num_pos] = pos_gt_labels
          pos_weight = 1.0 if cfg.pos_weight <= 0 else cfg.pos_weight
          label_weights[:num_pos] = pos_weight
          if not self.reg_decoded_bbox:
              pos_bbox_targets = self.bbox_coder.encode(
                  pos_priors, pos_gt_bboxes
              )
          else:
              # When the regression loss (e.g. `IouLoss`, `GIouLoss`)
              # is applied directly on the decoded bounding boxes, both
              # the predicted boxes and regression targets should be with
              # absolute coordinate format.
              pos_bbox_targets = get_box_tensor(pos_gt_bboxes)
          bbox_targets[:num_pos, :] = pos_bbox_targets
          bbox_weights[:num_pos, :] = 1
      if num_neg > 0:
          label_weights[-num_neg:] = 1.0
  
      return labels, label_weights, bbox_targets, bbox_weights
  
imports: from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from torch.nn.modules.utils import _pair
  from mmdet.models.layers import multiclass_nms
  from mmdet.models.losses import accuracy
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.utils import empty_instances, multi_apply
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import get_box_tensor, scale_boxes
  from mmdet.utils import ConfigType, InstanceList, OptMultiConfig
label_desc: Use image node_id 6 for calling the BBoxHead obj's underlying member method code with example usage: obj._get_targets_single(pos_priors, neg_priors, pos_gt_bboxes, pos_gt_labels, cfg) and returns: labels,  label_weights,  bbox_targets,  bbox_weights