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 all samples in a batch according to
  the sampling_results.
  
  Almost the same as the implementation in bbox_head, we passed
  additional parameters pos_inds_list and neg_inds_list to
  `_get_targets_single` function.
  
  Args:
      sampling_results (List[obj:SamplingResult]): Assign results of
          all images in a batch after sampling.
      rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.
      concat (bool): Whether to concatenate the results of all
          the images in a single batch.
  
  Returns:
      Tuple[Tensor]: Ground truth for proposals in a single image.
      Containing the following list of Tensors:
  
      - labels (list[Tensor],Tensor): Gt_labels for all
          proposals in a batch, each tensor in list has
          shape (num_proposals,) when `concat=False`, otherwise
          just a single tensor has shape (num_all_proposals,).
      - label_weights (list[Tensor]): Labels_weights for
          all proposals in a batch, each tensor in list has
          shape (num_proposals,) when `concat=False`, otherwise
          just a single tensor has shape (num_all_proposals,).
      - bbox_targets (list[Tensor],Tensor): Regression target
          for all proposals in a batch, each tensor in list
          has shape (num_proposals, 4) when `concat=False`,
          otherwise just a single tensor has shape
          (num_all_proposals, 4), the last dimension 4 represents
          [tl_x, tl_y, br_x, br_y].
      - bbox_weights (list[tensor],Tensor): Regression weights for
          all proposals in a batch, each tensor in list has shape
          (num_proposals, 4) when `concat=False`, otherwise just a
          single tensor has shape (num_all_proposals, 4).
docstr_tok: ["Calculate","the","ground","truth","for","all","samples","in","a","batch","according","to","the","sampling_results",".","Almost","the","same","as","the","implementation","in","bbox_head",",","we","passed","additional","parameters","pos_inds_list","and","neg_inds_list","to","`","_get_targets_single","`","function",".","Args",":","sampling_results","(","List","[","obj",":","SamplingResult","]",")",":","Assign","results","of","all","images","in","a","batch","after","sampling",".","rcnn_train_cfg","(","obj",":","ConfigDict",")",":","`","train_cfg","`","of","RCNN",".","concat","(","bool",")",":","Whether","to","concatenate","the","results","of","all","the","images","in","a","single","batch",".","Returns",":","Tuple","[","Tensor","]",":","Ground","truth","for","proposals","in","a","single","image",".","Containing","the","following","list","of","Tensors",":","-","labels","(","list","[","Tensor","]",",","Tensor",")",":","Gt_labels","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",",")",".","-","label_weights","(","list","[","Tensor","]",")",":","Labels_weights","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",",")",".","-","bbox_targets","(","list","[","Tensor","]",",","Tensor",")",":","Regression","target","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",","4",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","-","bbox_weights","(","list","[","tensor","]",",","Tensor",")",":","Regression","weights","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",","4",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",","4",")","."]
code: def get_targets(
      self,
      sampling_results: List[SamplingResult],
      rcnn_train_cfg: ConfigDict,
      concat: bool = True,
  ) -> tuple:
      """Calculate the ground truth for all samples in a batch according to
      the sampling_results.
  
      Almost the same as the implementation in bbox_head, we passed
      additional parameters pos_inds_list and neg_inds_list to
      `_get_targets_single` function.
  
      Args:
          sampling_results (List[obj:SamplingResult]): Assign results of
              all images in a batch after sampling.
          rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.
          concat (bool): Whether to concatenate the results of all
              the images in a single batch.
  
      Returns:
          Tuple[Tensor]: Ground truth for proposals in a single image.
          Containing the following list of Tensors:
  
          - labels (list[Tensor],Tensor): Gt_labels for all
              proposals in a batch, each tensor in list has
              shape (num_proposals,) when `concat=False`, otherwise
              just a single tensor has shape (num_all_proposals,).
          - label_weights (list[Tensor]): Labels_weights for
              all proposals in a batch, each tensor in list has
              shape (num_proposals,) when `concat=False`, otherwise
              just a single tensor has shape (num_all_proposals,).
          - bbox_targets (list[Tensor],Tensor): Regression target
              for all proposals in a batch, each tensor in list
              has shape (num_proposals, 4) when `concat=False`,
              otherwise just a single tensor has shape
              (num_all_proposals, 4), the last dimension 4 represents
              [tl_x, tl_y, br_x, br_y].
          - bbox_weights (list[tensor],Tensor): Regression weights for
              all proposals in a batch, each tensor in list has shape
              (num_proposals, 4) when `concat=False`, otherwise just a
              single tensor has shape (num_all_proposals, 4).
      """
      pos_priors_list = [res.pos_priors for res in sampling_results]
      neg_priors_list = [res.neg_priors for res in sampling_results]
      pos_gt_bboxes_list = [
          res.pos_gt_bboxes for res in sampling_results
      ]
      pos_gt_labels_list = [
          res.pos_gt_labels for res in sampling_results
      ]
      labels, label_weights, bbox_targets, bbox_weights = multi_apply(
          self._get_targets_single,
          pos_priors_list,
          neg_priors_list,
          pos_gt_bboxes_list,
          pos_gt_labels_list,
          cfg=rcnn_train_cfg,
      )
  
      if concat:
          labels = torch.cat(labels, 0)
          label_weights = torch.cat(label_weights, 0)
          bbox_targets = torch.cat(bbox_targets, 0)
          bbox_weights = torch.cat(bbox_weights, 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 7 for calling the BBoxHead obj's underlying member method code with example usage: obj.get_targets(sampling_results, rcnn_train_cfg, concat) and returns: labels,  label_weights,  bbox_targets,  bbox_weights